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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:42:45+00:00 2026-06-12T18:42:45+00:00

I have a question about rails and how its relationships query builder, specifically how

  • 0

I have a question about rails and how its relationships query builder, specifically how camel case is converted for the related calls.

Relevant Code

class CustomerPlan < ActiveRecord::Base
  attr_accessible :customer_id, :plan_id, :startDate, :user_id

  has_many :planActions
end

class PlanAction < ActiveRecord::Base
  attr_accessible :actionType_id, :customerPlan_id, :notes, :timeSpent

  belongs_to :customerPlan
  belongs_to :actionType
end

The getters and setters work just fine, such as plan_action.actionType.name will correctly pull from the related model. However customer_plan.planActions.each returns the error:

SQLite3::SQLException: no such column: plan_actions.customer_plan_id: 
  SELECT "plan_actions".* 
    FROM "plan_actions"  
    WHERE "plan_actions"."customer_plan_id" = 1

The column is defined in the database as customerPlan_id, was I just wrong to use this? It works for every other call, all my other relationships work fine. Even PlanAction -> CustomerPlan.

I ran through all the docs, and searched about every other source I know of. It would be simple enough to change my columns, I just want to know what’s going on here.

Thank you for your time!


A quick fix for this is to just explicitly set the foreign_key.

has_many :planActions, :foreign_key => "customerPlan_id", :class_name => "PlanAction"

Still, I think I am missing some model naming convention somewhere, just can’t seem to figure out what.

  • 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-06-12T18:42:47+00:00Added an answer on June 12, 2026 at 6:42 pm

    The Rails convention for DB column names is to use lowercase letters with words separated by an underscore (e.g. author_id, comments_count, updated_at, etc).

    I would highly recommend that you stick to the Rails conventions. This would make your life much easier. To change it to the rails convention, simply create a migration to rename the column to the appropriate style.

    However, if you do want to use a custom style for the column name, rails provides the :foreign_key option in the has_many relationship to specify the expected foreign column name:

    class CustomerPlan < ActiveRecord::Base
      has_many :plan_actions, :foreign_key => 'customerPlan_id'
    end
    

    You can also use the alias_attribute macro to alias the column name, if you’d like to use a different model attribute name than the actual DB column name. But as I mentioned, I would recommend sticking to the rails convention as much as possible. You’ll thank me later.

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

Sidebar

Related Questions

I have a question about ruby on rails and the process of assigning variables
Hi I have a question about ruby on rails Apparently I have a statement
Im new to rails and have a question about accessing relations of relations in
I have a simple question about how Rails 3 works with XHTML doctypes. Since
I am still learning Ruby on Rails, but have a general question about using
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,

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.