Browse the Ruby on Rails Community.

You are here: Forums Ask a Rails expert Associations...

Replytotopic

Associations

Posted in Forums : Ask a Rails expert

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

Hi I’m a newbie and need some help
Sorry this is so long,

i’m getting an error of uninitialized Constant Hierarchy::HierarchyBusinessFunctionTypeCostCenteAccount

I’m trying to achieve the equivalent of:-

select u.user_name, hbtcca.hierarchy_id, cost_centre_account_id from hierarchy_business_function_type_cost_centre_accounts hbtcca
inner join business_function_types bft on hbtcca.business_function_type_id = bft.id
inner join hierarchies h on hbtcca.hierarchy_id = h.id
inner join users u on h.controller = u.id
where bft.controlling_business_stream = 1 and u.id = 6

User table

user <

id integer,
user_name

User model

has_many :hierarchies_as_controller, :class_name => ‘Hierarchy’, :foreign_key => ‘controller’
has_many :hierarchies_as_reviewer, :class_name => ‘Hierarchy’, :foreign_key => ‘reviewer’
has_many :hierarchies_as_director, :class_name => ‘Hierarchy’, :foreign_key => ‘director’

Hierarchies table

id integer,
controller integer,
reviewer integer,
director integer

Hierarchies model

class Hierarchy < ActiveRecord::Base
belongs_to :reviewer, :class_name => ‘User’, :foreign_key => ‘reviewer’
belongs_to :director, :class_name => ‘User’, :foreign_key => ‘director’
belongs_to :controller, :class_name => ‘User’, :foreign_key => ‘controller’
has_many :hierarchy_business_function_type_cost_centre_accounts

Hierarchy_business_function_type_cost_centre_accounts (hbftcca) table

id,
business_function_type_id
cost_centre_account_id
hierarchy_id

hbftcca model

belongs_to :hierarchy
belongs_to :cost_centre_account
belongs_to :business_function_type

business_function_types table
id int,
business_function_type_description, string
controlling_business_function, boolean

 
Profile

Authority 25
Posting Rating 98
Sign in to rate this post

I didn’t really read the entire post but I can see a typo in this line:
Hierarchy::HierarchyBusinessFunctionTypeCostCenteAccount

I think you want Hierarchy::HierarchyBusinessFunctionTypeCostCentReAccount, correct?

 
Profile

Authority 12
Posting Rating 96
Sign in to rate this post

Raul: well spotted.

Colin: You win this month’s “Longest model name” award. Congratulations! Search for hierarchy_business_function_type_cost_cente_account in your source code, and change cente to centre.

 
Profile

Authority 12
Posting Rating 0
Sign in to rate this post

Thanks for the input and your time

Sorry, that was a typo in the post not in the models. It is correct in the code.

 
Profile

Authority 12
Posting Rating 96
Sign in to rate this post

Hi Colin

The relationship defined seems to fine,
Can you please inspect Hierarchy model object with methods? and check if hierarchy_business_function_type_cost_centre_accounts is there or try object.respond_to?(:hierarchy_business_function_type_cost_centre_accounts )

Are you running this in production ENV. try restarting the server then.

 
Matthias

Authority 37
Posting Rating 1
Sign in to rate this post

But this error:

uninitialized Constant B::A

is exactly that kind of error that you get if you call A.x inside B and you have a typo in A’s name.

Matthias

Replytotopic

Other Recent Topics

Ask a Rails expert : Get disk info

Ask a Rails expert : Problem with rails 2.1.0 & its older versions

Ask a Rails expert : How to test authentication and get the specific error using net:: http class

Ask a Rails expert : AJAX and set focus

Ask a Rails expert : How to use mephisto

Ask a Rails expert : Sanitizing html

Ask a Rails expert : First post, requesting sage perspective

Ask a Rails expert : How to use mephisto

Ask a Rails expert : will_paginate customization problem

Ask a Rails expert : BackgroundRB still wants 'development' environment...?

Formatting Help
  • *bold*       _italics_      
    bq. (quotes)
  • "DSC":http://www.dsc.net
  • * or # (lists)
or cancel