I have a few classes. One of them, articles, can have other articles
linked to it. Is the best way to model this with a
belongs_to_and_has_many, ie
class Article
belongs_to_and_has_many :articles
…
end
So i can then say (eg in a list view)
for article in @article.articles #do something with article
end
Will this work?
Assuming this is the best way to do it, in the join table, which will be
called articles_articles, i’m going to have to rename one or both of the
columns from the default of article_id (since i can’t have two fields
ith the same name). How do i tell rails the new column names?
Assuming this is the best way to do it, in the join table, which will be
called articles_articles, i’m going to have to rename one or both of the
columns from the default of article_id (since i can’t have two fields
ith the same name). How do i tell rails the new column names?
Appreciate any advice…
I did something like this for old application (done twice to make it two
way):
class Company
has_and_belongs_to_many :corporate_shares_held_in,
:class_name => ‘Company’,
:join_table => ‘company_share_holders’,
:foreign_key => ‘company_id’,
:association_foreign_key => ‘share_holder_company_id’
class Company
has_and_belongs_to_many :corporate_shares_held_in,
:class_name => ‘Company’,
:join_table => ‘company_share_holders’,
:foreign_key => ‘company_id’,
:association_foreign_key => ‘share_holder_company_id’
Thanks - i actually just did something very similar and it worked - i
set up join a table called article_links, where links are articles as
well. Then, like you say above: