felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-22 09:24 UTC
One model, several relations to another model...
Hi all, I don''t know a better title for my question, sorry about that. The problem I''m having is that I''ve got no clue how to do this: Table issues: Column created_by Column closed_by Both of those columns will hold User#id''s. For what I''ve read and understood in the API, you can do: Class Issue < AR::B belongs_to :created_by, :class_name => :user belongs_to :closed_by, :class_name => :user end But then, in my parent class: Class User < AR::B has_many :? # Issues trough created_by has_many :? # Issues trough updated_by end I''ve stopped here because I feel I''m not going in the right direction... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
has_many :created_issues, :class_name => "Issue", :foreign_key => "created_by" has_many :closed_issues, :class_name => "Issue", :foreign_key => "closed_by" On Dec 22, 2007 7:54 PM, felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I don''t know a better title for my question, sorry about that. > > The problem I''m having is that I''ve got no clue how to do this: > > Table issues: > Column created_by > Column closed_by > > Both of those columns will hold User#id''s. For what I''ve read and > understood in the API, you can do: > > Class Issue < AR::B > belongs_to :created_by, :class_name => :user > belongs_to :closed_by, :class_name => :user > end > > But then, in my parent class: > > Class User < AR::B > has_many :? # Issues trough created_by > has_many :? # Issues trough updated_by > end > > I''ve stopped here because I feel I''m not going in the right > direction... > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-22 09:32 UTC
Re: One model, several relations to another model...
When you say, it sounds so easy... Thanks a lot, again! =) On Dec 22, 1:27 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> has_many :created_issues, :class_name => "Issue", :foreign_key => > "created_by" > has_many :closed_issues, :class_name => "Issue", :foreign_key => "closed_by" > > On Dec 22, 2007 7:54 PM, felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hi all, > > > I don''t know a better title for my question, sorry about that. > > > The problem I''m having is that I''ve got no clue how to do this: > > > Table issues: > > Column created_by > > Column closed_by > > > Both of those columns will hold User#id''s. For what I''ve read and > > understood in the API, you can do: > > > Class Issue < AR::B > > belongs_to :created_by, :class_name => :user > > belongs_to :closed_by, :class_name => :user > > end > > > But then, in my parent class: > > > Class User < AR::B > > has_many :? # Issues trough created_by > > has_many :? # Issues trough updated_by > > end > > > I''ve stopped here because I feel I''m not going in the right > > direction... > > -- > Ryan Bigghttp://www.frozenplague.net--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-22 10:19 UTC
Re: One model, several relations to another model...
Ok, Here are the associations: Class Issue < AR::B belongs_to :creator, :class_name => :user, :foreign_key => :created_by belongs_to :solver, :class_name => :user, :foreign_key => :closed_by belongs_to :owner, :class_name => :user, :foreign_key => :assigned_to end Class User < AR::B has_many :created_issues, :class_name => :issue, :foreign_key => :created_by has_many :closed_issues, :class_name => :issue, :foreign_key => :closed_by has_many :assigned_issues, :class_name => :issue, :foreign_key => :assigned_to end If I do: @issues = Issue.find(:all, :include => :owner ) I get error: can''t convert Symbol into String Stack: C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:1347:in `type_name_with_module'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:1746:in `compute_type'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ reflection.rb:125:in `send'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ reflection.rb:125:in `klass'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1561:in `initialize'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1459:in `new'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1459:in `build_join_association'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1442:in `build'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1445:in `build'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1444:in `each'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1444:in `build'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1385:in `initialize'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1123:in `new'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1123:in `find_with_associations'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1122:in `catch'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ associations.rb:1122:in `find_with_associations'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:1232:in `find_every'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:503:in `find'' app/controllers/issues_controller.rb:5:in `index'' On Dec 22, 1:32 am, "felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When you say, it sounds so easy... > > Thanks a lot, again! =) > > On Dec 22, 1:27 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > has_many :created_issues, :class_name => "Issue", :foreign_key => > > "created_by" > > has_many :closed_issues, :class_name => "Issue", :foreign_key => "closed_by" > > > On Dec 22, 2007 7:54 PM, felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi all, > > > > I don''t know a better title for my question, sorry about that. > > > > The problem I''m having is that I''ve got no clue how to do this: > > > > Table issues: > > > Column created_by > > > Column closed_by > > > > Both of those columns will hold User#id''s. For what I''ve read and > > > understood in the API, you can do: > > > > Class Issue < AR::B > > > belongs_to :created_by, :class_name => :user > > > belongs_to :closed_by, :class_name => :user > > > end > > > > But then, in my parent class: > > > > Class User < AR::B > > > has_many :? # Issues trough created_by > > > has_many :? # Issues trough updated_by > > > end > > > > I''ve stopped here because I feel I''m not going in the right > > > direction... > > > -- > > Ryan Bigghttp://www.frozenplague.net--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
felipekk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-22 10:23 UTC
Re: One model, several relations to another model...
Fixed. Instead of using symbols for :class_name => I used strings. So :class_name => :user became :class_name => ''User''. On Dec 22, 2:19 am, "felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, > > Here are the associations: > > Class Issue < AR::B > belongs_to :creator, :class_name => :user, :foreign_key > => :created_by > belongs_to :solver, :class_name => :user, :foreign_key => :closed_by > belongs_to :owner, :class_name => :user, :foreign_key > => :assigned_to > end > > Class User < AR::B > has_many :created_issues, :class_name => :issue, :foreign_key > => :created_by > has_many :closed_issues, :class_name => :issue, :foreign_key > => :closed_by > has_many :assigned_issues, :class_name => :issue, :foreign_key > => :assigned_to > end > > If I do: > > @issues = Issue.find(:all, :include => :owner ) > > I get error: > > can''t convert Symbol into String > > Stack: > > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > base.rb:1347:in `type_name_with_module'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > base.rb:1746:in `compute_type'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > reflection.rb:125:in `send'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > reflection.rb:125:in `klass'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1561:in `initialize'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1459:in `new'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1459:in `build_join_association'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1442:in `build'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1445:in `build'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1444:in `each'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1444:in `build'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1385:in `initialize'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1123:in `new'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1123:in `find_with_associations'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1122:in `catch'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > associations.rb:1122:in `find_with_associations'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > base.rb:1232:in `find_every'' > C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ > base.rb:503:in `find'' > app/controllers/issues_controller.rb:5:in `index'' > > On Dec 22, 1:32 am, "felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > When you say, it sounds so easy... > > > Thanks a lot, again! =) > > > On Dec 22, 1:27 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > has_many :created_issues, :class_name => "Issue", :foreign_key => > > > "created_by" > > > has_many :closed_issues, :class_name => "Issue", :foreign_key => "closed_by" > > > > On Dec 22, 2007 7:54 PM, felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <felip...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi all, > > > > > I don''t know a better title for my question, sorry about that. > > > > > The problem I''m having is that I''ve got no clue how to do this: > > > > > Table issues: > > > > Column created_by > > > > Column closed_by > > > > > Both of those columns will hold User#id''s. For what I''ve read and > > > > understood in the API, you can do: > > > > > Class Issue < AR::B > > > > belongs_to :created_by, :class_name => :user > > > > belongs_to :closed_by, :class_name => :user > > > > end > > > > > But then, in my parent class: > > > > > Class User < AR::B > > > > has_many :? # Issues trough created_by > > > > has_many :? # Issues trough updated_by > > > > end > > > > > I''ve stopped here because I feel I''m not going in the right > > > > direction... > > > > -- > > > Ryan Bigghttp://www.frozenplague.net--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---