Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:35:43+00:00 2026-05-22T14:35:43+00:00

I have been trying to develop a movie based rails application which has support

  • 0

I have been trying to develop a movie based rails application which has support for multiple regions (Hollywood, Bollywood etc). I call the multiple regions as languages in the application.

Each language has its own set of data i.e., english has all the movies related to hollywood and language hindi has all the movies 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 both 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 this is 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 is language.article should return all the articles related to celebrities and movies.

The reason why I am not using SQL is find_by_sql does not support ActiveRelation and I will not be able use has_scope functionality.

I am using nested_has_many_through, has_scope and inherited_resources gems

Any help in this will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:35:44+00:00Added an answer on May 22, 2026 at 2:35 pm

    ok This is what I did to fix this.

    Added the following scope in my Article class

    def self.region(region_id)
      joins(<<-eos
        INNER JOIN
        (
          SELECT DISTINCT aa.article_id
          FROM regions r
               LEFT JOIN movies m on m.region_id = r.id
               LEFT JOIN cast_and_crews cc on cc.movie_id = m.id
               LEFT JOIN celebrities c on c.id = cc.celebrity_id
               LEFT JOIN events e on e.region_id = r.id
               LEFT JOIN article_associations aa on (aa.event_id = e.id or aa.movie_id = m.id or aa.celebrity_id = c.id)
          WHERE r.id = #{region_id}
        ) aa
      eos
      ).where("aa.article_id = articles.id")
    end
    

    This gives me a ActiveRecord::Relation instance that I am expected which retrieves all the records for a movie, celebrity or event.

    Thanks for all who helped me.

    If you have any comments to improve it please comment it. Very much appreciated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to develop a peer to peer application that uses Micosoft's
I have been trying to develop a Java ME application using WTK 2.5.2 (Java
I have been trying to develop an app for my ipad which i can
I have been trying to develop an application in a landscape mode so I
For the last three days I have been trying to develop a web based
HI, I am trying to develop a form which has some user controls ,
int duplicate (int cards[5][4][13]) I have been trying to develop a function (the prototype
I have been trying to develop an app that will deal with content providers
I have been trying to develop some user controls, one being a text edit
We recently started using Eclipse to develop our java application and have been running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.