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

And you can just do

@profile.send('friends').find(:all, :limit => 20, :order => 'RAND()',
include => :last_place) .to_xml(:include => :last_place)

* I put :last place in the finder to eager load, and again in the
to_xml so that is is included in the xml.

Another way which doesn't require the model modified or a builder and
is pretty ineffiecent for sql queries is

@items = @profile.send('friends').collect do |f|
  h = f.attributes
  h['place'] = f.checkins.last.place.attributes
  h
end
@items.to_xml

Let me know if you still have problems and include the models.
-Josh

On Jul 30, 2:18 pm, cnk <[email protected]> wrote:
> I think creating a builder file in your views directory will be the
> easiest way to get exactly the xml output you want.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to