What i want to do now is include the @place object in my xml
so like this:
wouter
*
...
..
I know i can do :include => [:place] but this include all the places
from that person. I only want to get the last place where the user
checked in ( @checkin = Checkin.find(:last, :conditions =>
{:profile_id => @list}) @place = @checkin.place) . So i really have to include this, but
I have tried many things but nothing works.
so i get the last_checkin from my database sorted by latest,
last_place is then the place source from my last_checkin.
when i get the to_xml and have as include :last_checkin i see the
latest checkin
I took a look at my own code where I test implemented this and
realized I have the same problem.
After watching SQL in the log and playing around in script/console I
realized this was happening
If I type user.last_checkin.last_place I was getting the correct place
if I typed user.last_place it wasn’t sorting by created_at anymore in
the query.
The same thing is happening in the to_xml…
This feels a little dirty to me, but it seems to work fine. Just
change the line in your model describing last_place to include the
ordered at on checkin table.
I think the most efficient way would be to create a has_one in the
model with a unique name and use the conditions or order to get just
one entry. I just tested this on one of my apps and it worked pretty
well.
I assume here that friends are just other profiles and a profile has
many checkins?
so you probably have something similar in profile.rb
has_many :checkins
has_many :places, :through => :checkins
Add (I think anyways)
has_one :last_checkin, :class_name => “CheckIn”, :order =>
‘created_at’
has_one :last_place, :through => :last_checkin, :source => :place