Hi, There is a couple of places where I want to reference table A from table B via two different relations. I am not sure exactly how to do this under rails, could anyone help. A simple example would be something like CREATE TABLE issues ( id INT NOT NULL AUTO_INCREMENT, reporter_id INT NOT NULL REFERENCES users(id), assignee_id INT NOT NULL REFERENCES users(id), PRIMARY KEY (id), FOREIGN KEY (reporter_id) REFERENCES users(id), FOREIGN KEY (assignee_id) REFERENCES users(id) ) ENGINE=InnoDB; I have tried a number of different combinations such as class Issue < ActiveRecord::Base belongs_to :reporter, :class_name => ''User'', :foreign_key => ''reporter_id'' assignee :reporter, :class_name => ''User'', :foreign_key => ''assignee_id'' end But that does not seem to load the relations. Is there something I am missing? TIA, Pete _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Did you mean (or have you tried) : belongs_to :reporter, :class_name => ''User'', :foreign_key => ''reporter_id'' belongs_to :assignee, :class_name => ''User'', :foreign_key => ''assignee_id'' On 10/11/05, Peter Donald <peter.j.donald-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > There is a couple of places where I want to reference table A from table B > via two different relations. I am not sure exactly how to do this under > rails, could anyone help. A simple example would be something like > > CREATE TABLE issues ( > id INT NOT NULL AUTO_INCREMENT, > reporter_id INT NOT NULL REFERENCES users(id), > assignee_id INT NOT NULL REFERENCES users(id), > PRIMARY KEY (id), > FOREIGN KEY (reporter_id) REFERENCES users(id), > FOREIGN KEY (assignee_id) REFERENCES users(id) > ) ENGINE=InnoDB; > > I have tried a number of different combinations such as > > class Issue < ActiveRecord::Base > belongs_to :reporter, :class_name => ''User'', :foreign_key => > ''reporter_id'' > assignee :reporter, :class_name => ''User'', :foreign_key => ''assignee_id'' > > end > > But that does not seem to load the relations. Is there something I am > missing? > > TIA, > > Pete > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Thats what I meant to type except my fingers and my brain didn''t cooperate. Actually looking at the code now I see that the problem is actually a typo in some completely different place. Sorry for the noise ... On 10/11/05, Kyle Maxwell <kyle-FOSOgQihYpQjo0HpFSRKWA@public.gmane.org> wrote:> > Did you mean (or have you tried) : > belongs_to :reporter, :class_name => ''User'', :foreign_key => ''reporter_id'' > belongs_to :assignee, :class_name => ''User'', :foreign_key => ''assignee_id'' > > On 10/11/05, Peter Donald <peter.j.donald-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > > There is a couple of places where I want to reference table A from table > B > > via two different relations. I am not sure exactly how to do this under > > rails, could anyone help. A simple example would be something like > > > > CREATE TABLE issues ( > > id INT NOT NULL AUTO_INCREMENT, > > reporter_id INT NOT NULL REFERENCES users(id), > > assignee_id INT NOT NULL REFERENCES users(id), > > PRIMARY KEY (id), > > FOREIGN KEY (reporter_id) REFERENCES users(id), > > FOREIGN KEY (assignee_id) REFERENCES users(id) > > ) ENGINE=InnoDB; > > > > I have tried a number of different combinations such as > > > > class Issue < ActiveRecord::Base > > belongs_to :reporter, :class_name => ''User'', :foreign_key => > > ''reporter_id'' > > assignee :reporter, :class_name => ''User'', :foreign_key => ''assignee_id'' > > > > end > > > > But that does not seem to load the relations. Is there something I am > > missing? > > > > TIA, > > > > Pete > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails