开发者

Rails 3 ActiveRecord find

In Rails 3, you do like...

User.select(...).include(..开发者_Python百科.).order(...)

However, if you select only 1 record, how do you do that?

User.find(10).include(:pictures) doesn't seem to work.

Should I use User.find(10, :include => [:pictures]) ?

Thanks.

Sam


Yes your User.find(10, :include=>:pictures]) example should work fine. You can also do User.includes(:pictures).find(10).

It doesn't matter too much either way but I'd probably go with the second method since it's more Rails 3ish and less likely to wind up deprecated.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜