I have two entities (Department and Project) that extends ActiveRecord::Base. The department is mapped to have many projects. When i make a query using the find(:all) (Department.find(:all)), i get a collection of the departments with the attributes(id, project_id) of the database. I would like to receive in each department one entity of the project class. I will appreciate any help ----------------------------------------------------------------------- class Department < ActiveRecord::Base has_many :project end class Project < ActiveRecord::Base end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eduardo Dias wrote:> > ----------------------------------------------------------------------- > class Department < ActiveRecord::Base > has_many :projects # <--- note.. your forgot to use the plural form here > end > > class Project < ActiveRecord::Basebelongs_to :department # <--- Did you forget to do this> endDepartment.find(:all).map {|d| d.projects.blank? ? nil : d.projects.first} hth ilan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ilan Berci wrote:> Eduardo Dias wrote: > >> >> ----------------------------------------------------------------------- >> class Department < ActiveRecord::Base >> has_many :projects # <--- note.. your forgot to use the plural form here >> end >> >> class Project < ActiveRecord::Base > belongs_to :department # <--- Did you forget to do this >> end > > Department.find(:all).map {|d| d.projects.blank? ? nil : > d.projects.first} > > hth > > ilanStill not work. I changed my classes and the project is not comming inside of the department I changed my classes to: ------------------------------------------------------------------------------- class Department < ActiveRecord::Base has_one :project end class Project < ActiveRecord::Base belongs_to :department end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---