0

任何人都可以帮助如何从rails上的has_many关系中获取属性值

例如公司是一个关系并且有很多电子邮件

company --> email

我需要从那些 company.email 获取 email_address

我怎样才能做到这一点?

company.email.email_address
4

3 回答 3

3

@company = Company.find(1) @company.emails.collect(&:email_address)

于 2009-08-10T12:53:00.810 回答
1

试试这个

@company = Email_address.find(:all,params[:email_id], :include => #:user, :conditions => "email_id=#{params[:email_id].to_i} AND published=true")

于 2009-08-10T13:57:53.287 回答
1
email_addresses = Company.all.map(&:emails).map(&:email_addresses)
于 2009-08-10T15:31:34.957 回答