Hello, Is it possible to have 2 tables, say author and books, both with fields "id" and "name". Seems to be an issue when you setup in the authors model for "has_many :books" to do something like @author.book.name since both author and book has the field "name". Shoudl this be a problem ? I remember getting an error in the past so i dont have exact output, but wondered if this is allowed to do .. thanks adam
On 14.9.2005, at 21.47, Adam Denenberg wrote:> Hello, > > Is it possible to have 2 tables, say author and books, both with > fields "id" and "name".All tables should have a field called "id" so it''s definitely a non- issue :-) The same holds for any other field name.> > Seems to be an issue when you setup in the authors model for > "has_many :books" to do something like > > @author.book.name since both author and book has the field "name". > Shoudl this be a problem ?No. @author.book refers to a book object which has a method "name". @author.name on the other hand calls the "name" method for the @author object. They are two totally different things and won''t interfere with one another in any way. So it''s highly unlikely that this is the cause of your problems. //jarkko> I remember getting an error in the past so i dont have exact > output, but wondered if this is allowed to do ..> > thanks > adam > _______________________________________________ > 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
Hi Adam, That should not be a problem... as you could access either of them via: @author.name # author name @author.book.name # book name However, if an author has_many books, then you would need to first find the book using something like: @author.books.find(1).name Tom On 9/14/05, Adam Denenberg <adam-fpx97dFL/ODYtjvyW6yDsg@public.gmane.org> wrote:> Hello, > > Is it possible to have 2 tables, say author and books, both with > fields "id" and "name". > > Seems to be an issue when you setup in the authors model for "has_many > :books" to do something like > > @author.book.name since both author and book has the field "name". > Shoudl this be a problem ? I remember getting an error in the past so i > dont have exact output, but wondered if this is allowed to do .. > > thanks > adam > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >