I am having a problem with a simple (at least I think it''s simple) belongs_to relationship. I''ve boiled it down to the following simple test case: Model - issue.rb ============class Issue < ActiveRecord::Base belongs_to :assigned_to, :class_name => "User", :foreign_key => "assigned_to" end Model - user.rb ============class User < ActiveRecord::Base end issues.ddl =============CREATE TABLE `issues` ( `id` int(11) default NULL, `assigned_to` int(11) default NULL ) TYPE=MyISAM users.ddl ==============CREATE TABLE `users` ( `id` int(11) default NULL, `login` varchar(50) default NULL ) TYPE=MyISAM With this setup, I try the following in the rails console: % script/console development Loading environment... irb(main):001:0> i = Issue.find(1) => #<Issue:0x2791048> irb(main):002:0> i.assigned_to zsh: illegal hardware instruction script/console development Am I missing something here? Thanks! Todd Breiholz Rails and Ruby Nuby
whats your platfrom and ruby -v ? On Fri, 14 Jan 2005 18:51:05 -0600, Todd Breiholz <talanb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am having a problem with a simple (at least I think it''s simple) > belongs_to relationship. I''ve boiled it down to the following simple > test case: > > Model - issue.rb > ============> class Issue < ActiveRecord::Base > belongs_to :assigned_to, :class_name => "User", :foreign_key => "assigned_to" > end > > Model - user.rb > ============> class User < ActiveRecord::Base > end > > issues.ddl > =============> CREATE TABLE `issues` ( > `id` int(11) default NULL, > `assigned_to` int(11) default NULL > ) TYPE=MyISAM > > users.ddl > ==============> CREATE TABLE `users` ( > `id` int(11) default NULL, > `login` varchar(50) default NULL > ) TYPE=MyISAM > > With this setup, I try the following in the rails console: > > % script/console development > Loading environment... > irb(main):001:0> i = Issue.find(1) > => #<Issue:0x2791048> > irb(main):002:0> i.assigned_to > zsh: illegal hardware instruction script/console development > > Am I missing something here? > > Thanks! > > Todd Breiholz > Rails and Ruby Nuby > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
Strangely enough, if I change the column issues.assigned_to to issues.user_id and then change the Issue belongs_to call to : class Issue < ActiveRecord::Base belongs_to :User end Everything works as expected. There must be something going on with the :class_name or :foreign_key options. Todd On Fri, 14 Jan 2005 18:51:05 -0600, Todd Breiholz <talanb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am having a problem with a simple (at least I think it''s simple) > belongs_to relationship. I''ve boiled it down to the following simple > test case: > > Model - issue.rb > ============> class Issue < ActiveRecord::Base > belongs_to :assigned_to, :class_name => "User", :foreign_key => "assigned_to" > end > > Model - user.rb > ============> class User < ActiveRecord::Base > end > > issues.ddl > =============> CREATE TABLE `issues` ( > `id` int(11) default NULL, > `assigned_to` int(11) default NULL > ) TYPE=MyISAM > > users.ddl > ==============> CREATE TABLE `users` ( > `id` int(11) default NULL, > `login` varchar(50) default NULL > ) TYPE=MyISAM > > With this setup, I try the following in the rails console: > > % script/console development > Loading environment... > irb(main):001:0> i = Issue.find(1) > => #<Issue:0x2791048> > irb(main):002:0> i.assigned_to > zsh: illegal hardware instruction script/console development > > Am I missing something here? > > Thanks! > > Todd Breiholz > Rails and Ruby Nuby >
I''ve now discovered that if I change the column name in the table to assigned_to_id and change the belongs_to call accordingly, everything seems to work. Is there a requirement that the foreign key column name end in _id? Todd On Sat, 15 Jan 2005 14:20:50 -0600, Todd Breiholz <talanb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Strangely enough, if I change the column issues.assigned_to to > issues.user_id and then change the Issue belongs_to call to : > > class Issue < ActiveRecord::Base > belongs_to :User > end > > Everything works as expected. There must be something going on with > the :class_name or :foreign_key options. > > Todd > > > On Fri, 14 Jan 2005 18:51:05 -0600, Todd Breiholz <talanb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am having a problem with a simple (at least I think it''s simple) > > belongs_to relationship. I''ve boiled it down to the following simple > > test case: > > > > Model - issue.rb > > ============> > class Issue < ActiveRecord::Base > > belongs_to :assigned_to, :class_name => "User", :foreign_key => "assigned_to" > > end > > > > Model - user.rb > > ============> > class User < ActiveRecord::Base > > end > > > > issues.ddl > > =============> > CREATE TABLE `issues` ( > > `id` int(11) default NULL, > > `assigned_to` int(11) default NULL > > ) TYPE=MyISAM > > > > users.ddl > > ==============> > CREATE TABLE `users` ( > > `id` int(11) default NULL, > > `login` varchar(50) default NULL > > ) TYPE=MyISAM > > > > With this setup, I try the following in the rails console: > > > > % script/console development > > Loading environment... > > irb(main):001:0> i = Issue.find(1) > > => #<Issue:0x2791048> > > irb(main):002:0> i.assigned_to > > zsh: illegal hardware instruction script/console development > > > > Am I missing something here? > > > > Thanks! > > > > Todd Breiholz > > Rails and Ruby Nuby > > >
If I point my browser towards: http://tabby:3005/ It redirects and displays the content at: http://tabby:3005/_doc/index.html If I then point my browser at: http://tabby:3005/todo or http://tabby:3005/todo/list I get a timeout, and this in my apache.log: [Sat Jan 15 14:42:40 2005] [error] [client 10.0.0.150] FastCGI: comm with (dynamic) server "/var/www/Thingy/public/dispatch.fcgi" aborted: (first read) idle timeout (30 sec) [Sat Jan 15 14:42:40 2005] [error] [client 10.0.0.150] FastCGI: incomplete headers (0 bytes) received from server "/var/www/Thingy/public/dispatch.fcgi" However if I point my browser at: http://tabby:3005/todo/list.rhtml I get the raw text of the document (html / erb completely uninterpereted). Does anybody have advice?
Hmm odd, Shouldn''t be an requirement, but i guess its what most people use On Sat, 15 Jan 2005 14:38:32 -0600, Todd Breiholz <talanb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve now discovered that if I change the column name in the table to > assigned_to_id and change the belongs_to call accordingly, everything > seems to work. Is there a requirement that the foreign key column name > end in _id? > > Todd > > > On Sat, 15 Jan 2005 14:20:50 -0600, Todd Breiholz <talanb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Strangely enough, if I change the column issues.assigned_to to > > issues.user_id and then change the Issue belongs_to call to : > > > > class Issue < ActiveRecord::Base > > belongs_to :User > > end > > > > Everything works as expected. There must be something going on with > > the :class_name or :foreign_key options. > > > > Todd > > > > > > On Fri, 14 Jan 2005 18:51:05 -0600, Todd Breiholz <talanb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I am having a problem with a simple (at least I think it''s simple) > > > belongs_to relationship. I''ve boiled it down to the following simple > > > test case: > > > > > > Model - issue.rb > > > ============> > > class Issue < ActiveRecord::Base > > > belongs_to :assigned_to, :class_name => "User", :foreign_key => "assigned_to" > > > end > > > > > > Model - user.rb > > > ============> > > class User < ActiveRecord::Base > > > end > > > > > > issues.ddl > > > =============> > > CREATE TABLE `issues` ( > > > `id` int(11) default NULL, > > > `assigned_to` int(11) default NULL > > > ) TYPE=MyISAM > > > > > > users.ddl > > > ==============> > > CREATE TABLE `users` ( > > > `id` int(11) default NULL, > > > `login` varchar(50) default NULL > > > ) TYPE=MyISAM > > > > > > With this setup, I try the following in the rails console: > > > > > > % script/console development > > > Loading environment... > > > irb(main):001:0> i = Issue.find(1) > > > => #<Issue:0x2791048> > > > irb(main):002:0> i.assigned_to > > > zsh: illegal hardware instruction script/console development > > > > > > Am I missing something here? > > > > > > Thanks! > > > > > > Todd Breiholz > > > Rails and Ruby Nuby > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
Here''s some more details if it''ll help. I can''t get fcgi or mod_ruby to work with rails at all, same kind of errors as detailed in the first message. cgi seems to work relatively well though. If I go to http://tabby:3005/todo/list then I receive: LoadError in List#index No such file to load -- ninja/list_controller.rb Then I go to http://tabby:3005/todo and receive the expected content. Also, at this point a /tmp/ruby_sess.[hex] file is created. After that, http://tabby:3005/todo/list works as expected. Trevor wrote:> If I point my browser towards: > > http://tabby:3005/ > It redirects and displays the content at: > http://tabby:3005/_doc/index.html > > If I then point my browser at: > http://tabby:3005/todo > > or > http://tabby:3005/todo/list > > I get a timeout, and this in my apache.log: > [Sat Jan 15 14:42:40 2005] [error] [client 10.0.0.150] FastCGI: comm > with (dynamic) server "/var/www/Thingy/public/dispatch.fcgi" aborted: > (first read) idle timeout (30 sec) > [Sat Jan 15 14:42:40 2005] [error] [client 10.0.0.150] FastCGI: > incomplete headers (0 bytes) received from server > "/var/www/Thingy/public/dispatch.fcgi" > > However if I point my browser at: > http://tabby:3005/todo/list.rhtml > > I get the raw text of the document (html / erb completely > uninterpereted). > > Does anybody have advice? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Todd Breiholz wrote:> I''ve now discovered that if I change the column name in the table to > assigned_to_id and change the belongs_to call accordingly, everything > seems to work. Is there a requirement that the foreign key column name > end in _id?No, the requirement is that the association name must be different to the foreign key name (in your first example they were both "assigned_to") and Rails gets confused about which attribute (the association itself or its foreign key) you''re talking about. This is only an issue on belongs_to relationships, where the foreign key is stored in the table of the class the association belongs to. Tim. -- Tim Bates tim-kZbwfhiKUx26c6uEtOJ/EA@public.gmane.org