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

  • Home
  • SEARCH
  • 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 1012831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:00:21+00:00 2026-05-16T10:00:21+00:00

Hi guys I know that this is really bad idea but I want join

  • 0

Hi guys I know that this is really bad idea but I want join three tables for my query on polymorphic association

for example

class Article
  has_many :comments, :as=>:commentable
end

class Post
  has_many :comments, :as=>:commentable
end

class Comment
  belongs_to :commentable, :polymorphic=>:true
end

and I need to get something similar to

Comment.all(:joins=>:commentable)

of course I can’t write exactly such join but I need something that can join this three tables

I’m writing cimplicate search by several tables User can choose different options Let’s say that User has_one Comment and I want select all users who commented something (Article or Post) that includes some phrase So I need something similar to User.all(:joins=>{:comments=>:commentable}, :conditions=>["articles.body LIKE (?) OR posts.header LIKE (?)", value, value])

  • 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-16T10:00:21+00:00Added an answer on May 16, 2026 at 10:00 am

    I suppose that the thing I want to do is impossible because

    join format

    SELECT column_name(s)
    FROM table_name1
    INNER JOIN table_name2
    ON table_name1.column_name=table_name2.column_name
    

    and I must join tables on commentable_id without any difference for different tables That would be a mess But maybe I am wrong

    Edits
    I did next

    User.all(:joins=>"clean sql inner join of three tables on commentable_id", 
    :conditions=>[" (comments.commentable_class="Article" AND articles.body LIKE (?)) 
                 OR (comments.commentable_class="Post" AND posts.header LIKE (?))", value, value])
    

    I’m still refactoring code and I’ll post the result later

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

Sidebar

Related Questions

Ok guys, I know this is pretty a rare case but I really would
guys I know this question is very basic but I've met in few publications
Guys I know this question is silly but just to make sure: Having in
Now i know that this one is actually not a very technical question but
Ok guys I know this question has been asked before but I am very
I know this is a really rookie question but would like some understanding off
hey guys i know this may sound stupid, but i am stuck with this
First of all, I want you to know that I really like OpenCV. I
Hi guys i am going to make a android game. i wanna know that
Sorry guys, didn't know how to word this one. Still learning jquery and have

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.