Senthil Kumar Bhaskaran
Senthil Kumar Bhaskaran

Reputation: 7451

how to fetch Has_many relationship values on RAILS

Can any one please help to how to fetch the values of attributes from the has_many Relationship on rails

For example company is one relation and has many email

company --> email

i need to fetch email_address from those company.email

How can i do that?

company.email.email_address

Upvotes: 0

Views: 214

Answers (3)

ez.
ez.

Reputation: 7654

email_addresses = Company.all.map(&:emails).map(&:email_addresses)

Upvotes: 1

Ahmad Ramdani
Ahmad Ramdani

Reputation: 208

Try this

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

Upvotes: 1

philipth
philipth

Reputation: 276

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

Upvotes: 3

Related Questions