Я пытался разработать приложение, основанное на фильмах, которое поддерживает несколько регионов (Голливуд, Болливуд и т. Д.).Я называю несколько регионов в качестве языков в приложении.
Каждый язык имеет свой собственный набор данных, т. Е. Английский имеет все фильмы, связанные с Голливудом, а язык хинди имеет все фильмы, связанные с Болливудом.
Модель языка
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
Здесь и у фильмов, и у знаменитостей есть статьи, использующие класс article_association.
Модель фильма
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
модель знаменитости
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
и вот как определяется моя модель изделия
class Article < ActiveRecord::Base
has_many :article_associations
has_many :celebrities, :through => :article_associations
has_many :movies, :through => :article_associations
end
ЧтоЯ пытаюсь добиться того, чтобы language.article должен возвращать все статьи, связанные со знаменитостями и фильмами.
Причина, по которой я не использую SQL, заключается в том, что find_by_sql не поддерживает ActiveRelation, и я не смогу использовать функциональность has_scope.
Я использую драгоценные камни nested_has_many_through, has_scope и inherited_resources
Любая помощь в этом будет принята с благодарностью.