I am trying to develop a movie-based application that supports several regions (Hollywood, Bollywood, etc.). I name several areas as languages โโin the application.
Each language has its own data set, i.e. in English there are all films related to Hollywood and Hindi in the language, all films related to Bollywood.
Language model
class Language < ActiveRecord::Base has_many :movies has_many :cast_and_crews, :through => :movies, :uniq => true has_many :celebrities, :through => :cast_and_crews, :uniq => true # FIXME: Articles for celebrities and movies has_many :article_associations, :through => :celebrities has_many :articles, :through => :article_associations, :uniq => true end
Here, movies and celebrities have articles using the article_association class.
Movie model
class Movie < ActiveRecord::Base belongs_to :language has_many :cast_and_crews has_many :celebrities, :through => :cast_and_crews has_many :article_associations has_many :articles, :through => :article_associations, :uniq => true end
Celebrity model
class Celebrity < ActiveRecord::Base has_many :cast_and_crews has_many :movies, :through => :cast_and_crews, :uniq => true has_many :article_associations has_many :articles, :through => :article_associations, :uniq => true end class ArticleAssociation < ActiveRecord::Base belongs_to :article belongs_to :celebrity belongs_to :movie end
and thatโs how my article model is defined
class Article < ActiveRecord::Base has_many :article_associations has_many :celebrities, :through => :article_associations has_many :movies, :through => :article_associations end
What I am trying to achieve, language.article, should return all the articles related to celebrities and films.
The reason I am not using SQL is that find_by_sql does not support ActiveRelation, and I cannot use the has_scope functions.
I use nested_has_many_through, has_scope and inherited_resources gems
Any help on this would be greatly appreciated.