Hi, I have a database setup with 2 tables and a simple one-to-many relationship where article_categories have many articles. In the models ruby has created for me, I''ve added "belongs_to :article_category" to the Article class and "has_many :articles" to the ArticleCategory class. Everything seems fine until I try to reference the category from the article. In my view for example, I have "@article.article_category.name", but this throws an error.. ------ You have a nil object when you didn''t expect it! The error occured while evaluating nil.name ------ The referential integrity is fine. I imagine having an categories table as opposed to article_categories may help, but I have other types of categories in my database. Any pointers would be a great help. Thanks in advance, PeteC
> I have a database setup with 2 tables and a simple one-to-many > relationship where > article_categories have many articles. > > In the models ruby has created for me, I''ve added "belongs_to > :article_category" to the Article class and "has_many :articles" to > the ArticleCategory class. > > Everything seems fine until I try to reference the category from the > article. In my view for example, I have > "@article.article_category.name", but this throws an error.. > > ------ > You have a nil object when you didn''t expect it! > The error occured while evaluating nil.name > ------ > > The referential integrity is fine. I imagine having an categories > table as opposed to article_categories may help, but I have other > types of categories in my database. > > Any pointers would be a great help.I managed to solve the problem after a little more poking. I''d incorrectly named the article_category_id column in the article table as category_id. All works fine now. Cheers, PeteC