开发者

Association function in Rails

I have Users, Hosts, and Checkins.

Users -> has_many -> Hosts -> has_many -> Checkins

Checkin -> belongs_to 开发者_开发知识库-> Host -> belongs_to -> User

How can I easily do a query for all checkins for a particular user without writing my own SQL?


Use a has_many :through association, like this:

has_many :checkins, :through => :hosts

You can then simply use checkins as your direct association. Whoo hoo!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜