As seen from above in Project class there is no relation ship defined for role so how can you expect the result from it.
Add has_many :roles, :through => :projects_ressources and the required output will be produced. On Jan 7, 10:54 am, Sven Schleier <[email protected]> wrote: > Hello, > I'm doing right now my first steps in Ruby on Rails and I've got a > problem. > Just some explanation: > A project can have ressources (like an employee) and this ressource can > have certain roles (e.g. a team member, or a team leader). > As you can see in the attachment, I have a Table called > Projects_Ressources. This Table has three relationships (belongs_to). > One to Projects, one to Ressources and one to Roles. > > This is my model description for, > > role.rb: > <code> > class Role < ActiveRecord::Base > has_many :projects_ressources > has_many :ressources, :through => :projects_ressources > has_many :permissions_roles > has_many :permissions, :through => :permissions_roles > end > </code> > > project.rb: > <code> > class Project < ActiveRecord::Base > has_many :projects_ressources > has_many :ressources, :through => :projects_ressources > end > </> > > ressource.rb: > <code> > class Ressource < ActiveRecord::Base > has_many :projects_ressources > has_many :projects, :through => :projects_ressources > has_many :roles, :through => :projects_ressources > end > </code> > > projects_ressources.rb: > <code> > class ProjectsRessource < ActiveRecord::Base > belongs_to :ressource > belongs_to :project > belongs_to :role > end > </code> > > When I'm now in the console, I can get for example the project with id 1 > > >> pro = Project.find(1) > > And can get all the ressources to this certain project: > > >> employee = pro.ressources > > But I want also to know the roles of this ressources. How can I get now > the roles of the ressources to this project with id 1? This doesn't > work: > > >> role = pro.roles > > produces this error in the console: > > <code> > NoMethodError: undefined method `roles' for #<Project:0x4dffdc0> > from > c:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record > /attribute_methods.rb:260:in `method_missing' > from (irb):47 > from :0 > </code> > > Is the design of the relationship wrong or what am I missing? > > Attachments:http://www.ruby-forum.com/attachment/4360/erm.PNG > > -- > Posted viahttp://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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

