I have the following: class Entry < ActiveRecord::Base belongs_to(:RanShow,:foreign_key=>"show_id") end class RanShow < ActiveRecord::Base has_many(:entries) end The shows table has a field named show_id I''m trying to do something like: rs = RanShow.find(1) render_text rs.entries.length However it does not work, saying Unknown column ''entries.ran_show_id'' Since I''ve specified that the foreign key was "show_id" I kind of expected it to use it. Is there something I am not getting right? Thanks, Bogdan _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I meant that the entries (not shows) table has a field named show_id. On 10/1/05, Bogdan Ionescu <bogdan.ionescu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I have the following: > > class Entry < ActiveRecord::Base > belongs_to(:RanShow,:foreign_key=>"show_id") > end > > class RanShow < ActiveRecord::Base > has_many(:entries) > end > > The shows table has a field named show_id > I''m trying to do something like: > > rs = RanShow.find(1) > render_text rs.entries.length > > However it does not work, saying Unknown column ''entries.ran_show_id'' > Since I''ve specified that the foreign key was "show_id" I kind of expected > it to use it. Is there something I am not getting right? > > Thanks, > Bogdan >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Ok, ignore this question. I''ve realised that a foreign_key had to be declared in has_many too. On 10/1/05, Bogdan Ionescu <bogdan.ionescu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I meant that the entries (not shows) table has a field named show_id. > > > On 10/1/05, Bogdan Ionescu <bogdan.ionescu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have the following: > > > > class Entry < ActiveRecord::Base > > belongs_to(:RanShow,:foreign_key=>"show_id") > > end > > > > class RanShow < ActiveRecord::Base > > has_many(:entries) > > end > > > > The shows table has a field named show_id > > I''m trying to do something like: > > > > rs = RanShow.find(1) > > render_text rs.entries.length > > > > However it does not work, saying Unknown column ''entries.ran_show_id'' > > Since I''ve specified that the foreign key was "show_id" I kind of > > expected it to use it. Is there something I am not getting right? > > > > Thanks, > > Bogdan > > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails