On Thursday, August 14, 2014 3:18:50 AM UTC-7, Куракин Александр wrote:
>
> I use Sequel and have:
>
> User.many_to_many :rooms
> Room.many_to_one :town
>
> I want to get *towns of all user's rooms*.
>
> How can I do it with Sequel?
> What have I read to?
> Thanks.
>
The easiest way is:
user.rooms.map{|r| r.town}
That's going to do one query per room to get the town by default, but you
can use the tactical_eager_loading plugin or the :eager=>:town association
option on the rooms associations to make it do a single query for all of
the towns (for a combination of two queries). If you really need to get it
down to a single query, you can use the many_through_many plugin.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.