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 7610745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:29:31+00:00 2026-05-31T01:29:31+00:00

This should be a very basic question, I’m still new to ruby so i’d

  • 0

This should be a very basic question, I’m still new to ruby so i’d appreciate some help.

So I have 3 tables in my db, Source, SourceType and Feed. Every Source belongs to a SourceType and Every Feed Belongs to a Source. Their primary keys are SourceID, TypeID and FeedID

my Active Record Classes are:

class SourceFeed < ActiveRecord::Base
  self.table_name = "SourceFeed"
  self.primary_key = "FeedID"

  belongs_to :Source, 
  :foreign_key => "SourceID", 
  :class_name => "Source",
  :include => "SourceType"
end

class Source < ActiveRecord::Base
  self.table_name = "Source"
  self.primary_key = "SourceID"

  has_many :SourceFeeds, 
  :primary_key => "SourceID", 
  :class_name => "SourceFeed"

  belongs_to :SourceType,
  :foreign_key => "TypeID", 
  :class_name => "SourceType"
end

class SourceType < ActiveRecord::Base
  self.table_name = "SourceType"
  self.primary_key = "TypeID"

  has_many :Source, 
  :primary_key => "TypeID", 
  :class_name => "Source"
end

I am trying to select stuff from SourceFeed, Stuff from Source and the SourceType. Here’s the query:

feed = SourceFeed.select("SourceFeed.FeedID, Source.Name as SourceName, SourceType.Name as SourceType").joins(:Source, :SourceType).where(:FeedID => FeedID).first

I am getting a Association named 'SourceType' was not found; perhaps you misspelled it? Error

If I remove it from the Joins, I get an Unknown column 'SourceType.Name' in 'field list' error.

What’s the right way to do it?

Thanks

PS: My database doesn’t follow active records naming conventions, but I can’t change that I am working with an existing DB.

  • 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-31T01:29:33+00:00Added an answer on May 31, 2026 at 1:29 am

    Your query only works if there’s an association named “SourceType” defined in SourceFeed. You don’t have it, so you got the error.
    I think this should work:

    feed = SourceFeed.select("SourceFeed.FeedID, Source.Name as SourceName, SourceType.Name as SourceType").joins(:Source).joins("JOIN SourceType ON SourceType.TypeID = Source.TypeID").where(:FeedID => FeedID).first
    

    UPDATE:
    Definitely, Derek Harmel’s answer is a better one. SQL should be avoided whenever possible.

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

Sidebar

Related Questions

This should be a very basic design question, but for some reason it doesn't
Please forgive this rather basic question, but I'm very new to Java and still
This seems like a very basic question but I couldn't find any help on
I am aware this is a very basic question, we are very new to
I guess that this is a very absurd/basic question, but still: class m {
This may be a very basic question, but it still gets me confused (and
This should be very simple question. There are many programming languages out there, compiled
This should reduce the executable size quite a bit in some of my very
I have a very basic question on returning a reference to an element of
This is a very basic question - but apparently google is not very good

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.