开发者

Rails Associtions

Firm has_many :clients

Client belongs_to :firm # w Forign key firm_id

I can do client.firm.name

my question:

what is the best way to find clien开发者_Go百科ts that belong to this firm in the same format?


To get all of the client objects, just do...

c = firm.clients

To get all of the client names for a firm as an array of strings, do...

names = firm.clients.all.collect {|c| c.name}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜