Hi, I''m trying to map a foreign key in my projects table to a user, as project_manager. Ive tried in the ProjectController composed_of :project_manager, :class_name=>''user'', :mapping => %w(project_manager id) I lifted this from the Active controller documentation with changes to my situation. The problem that I''m haveing is that everytime I try to call project.project_manager.name (or something similar) is the following. undefined method `stringify_keys!'' for 1:Fixnum I tried to do this without including the :mapping parameter but with no luck. Am I doing something wrong or is this not the way to do this. Thanx in advance Liquid _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Are you sure you have a "composed_of" rather than a "belongs_to"? Can you post what the actual database tables look like? Liquid wrote:> Hi, > > I''m trying to map a foreign key in my projects table to a user, as > project_manager. > > Ive tried in the ProjectController > composed_of :project_manager, :class_name=>''user'', :mapping => > %w(project_manager id) > > I lifted this from the Active controller documentation with changes to > my situation. > > The problem that I''m haveing is that everytime I try to call > project.project_manager.name (or something similar) is the following. > >|undefined method `stringify_keys!'' for 1:Fixnum > >I tried to do this without including the :mapping parameter but with no luck. > >Am I doing something wrong or is this not the way to do this. > > >Thanx in advance > >Liquid >| > > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
yes, It''s definitely composed_of , the users class does not have a has_many relationship in it. The database tables looke like: Projects id INT AutoIncrement title VARCHAR(45) NOT NULL parent_id INT project_manager INT (the key to the user) .... Users id INT AutoIncrement login VARCHAR(45) password VARCHAR(255) created_on TIMESTAMP updated_on TIMESTAMP I''m using mysql & I have not explicitly set the foreign key there since it doesn''t use them with MYSAM tables. I want to use these because of the full text serach. Please note the call below project.project_manager.name should be project.project_manager.login On 8/13/05, Steve Downey <sldowney-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:> > Are you sure you have a "composed_of" rather than a "belongs_to"? Can > you post what the actual database tables look like? > > Liquid wrote: > > > Hi, > > > > I''m trying to map a foreign key in my projects table to a user, as > > project_manager. > > > > Ive tried in the ProjectController > > composed_of :project_manager, :class_name=>''user'', :mapping => > > %w(project_manager id) > > > > I lifted this from the Active controller documentation with changes to > > my situation. > > > > The problem that I''m haveing is that everytime I try to call > > project.project_manager.name (or something similar) is the following. > > > >|undefined method `stringify_keys!'' for 1:Fixnum > > > >I tried to do this without including the :mapping parameter but with no > luck. > > > >Am I doing something wrong or is this not the way to do this. > > > > > >Thanx in advance > > > >Liquid > >| > > > > > >------------------------------------------------------------------------ > > > >_______________________________________________ > >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
I''ve tried something else that seems to work. Rather than use composed_of I tried belongs_to :project_manager, :class_name => ''User'' ,:foreign_key => ''project_manager'' which seems to work. This is not the only such foreign_key that relates to User, there is also created_by, updated_by etc. Is there any reason why I should not do it this way? Cheers On 8/14/05, Liquid <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > yes, It''s definitely composed_of , the users class does not have a > has_many relationship in it. > > The database tables looke like: > Projects > id INT AutoIncrement > title VARCHAR(45) NOT NULL > parent_id INT > project_manager INT (the key to the user) > .... > > Users > id INT AutoIncrement > login VARCHAR(45) > password VARCHAR(255) > created_on TIMESTAMP > updated_on TIMESTAMP > > I''m using mysql & I have not explicitly set the foreign key there since it > doesn''t use them with MYSAM tables. I want to use these because of the full > text serach. > > Please note the call below project.project_manager.name should be > project.project_manager.login > > > > > On 8/13/05, Steve Downey <sldowney-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote: > > > > Are you sure you have a "composed_of" rather than a "belongs_to"? Can > > you post what the actual database tables look like? > > > > Liquid wrote: > > > > > Hi, > > > > > > I''m trying to map a foreign key in my projects table to a user, as > > > project_manager. > > > > > > Ive tried in the ProjectController > > > composed_of :project_manager, :class_name=>''user'', :mapping => > > > %w(project_manager id) > > > > > > I lifted this from the Active controller documentation with changes to > > > > > my situation. > > > > > > The problem that I''m haveing is that everytime I try to call > > > project.project_manager.name (or something similar) is the following. > > > > > >|undefined method `stringify_keys!'' for 1:Fixnum > > > > > >I tried to do this without including the :mapping parameter but with no > > luck. > > > > > >Am I doing something wrong or is this not the way to do this. > > > > > > > > >Thanx in advance > > > > > >Liquid > > >| > > > > > > > > > > >------------------------------------------------------------------------ > > > > > >_______________________________________________ > > >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
On 8/14/05, Liquid <has.sox-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve tried something else that seems to work. Rather than use composed_of I > tried > belongs_to :project_manager, :class_name => ''User'' ,:foreign_key => > ''project_manager'' > which seems to work. > > This is not the only such foreign_key that relates to User, there is also > created_by, updated_by etc. > > Is there any reason why I should not do it this way?belongs_to is what you''re looking for. compose_of is something completely different: http://rails.rubyonrails.com/classes/ActiveRecord/Aggregations/ClassMethods.html -- rick http://techno-weenie.net