Andrew Sinning Thu Jul 21 10:10:56 -0400 2011

Subject: how to override default class_name when using "through" parameter

I have a class called "SettingToType" which is just used to associate to other tables "settings" and "settingTypes".

In my class "Setting", I'm trying to establish a has_one relationship to a SettingType.

Because I find non-camel-case variables very hard to read, I don't want to use a variable called "settingtotype" to reference the class "SettingToType". I'd much rather use "setting_to_type" or "settingToType". So, I should be able to do this:

static $has_one = array(
array('setting_to_type', 'class_name'=>'SettingToType')
);

So far, so good.

But now I need to get "settingtype" through the association "setting_to_type". So, the complete statement is:

static $has_one = array(
array('setting_to_type', 'class_name'=>'SettingToType'),
array('settingtype', 'through'=>'setting_to_type')
);

When I do this, I get an error "Could not find the association setting_to_type in model Setting"

However, if use "settingtotype" instead of "setting_to_type" for the 2nd item below

static $has_one = array(
array('setting_to_type', 'class_name'=>'SettingToType'),
array('settingtype', 'through'=>'settingtotype')
);

then this works just fine, even though I haven't changed the name of first item.

So, this makes me wonder what the point of the first item is.

But, more to the point, why can't "settingtype" be accessed through "setting_to_type" the way this is constructed.

Thanks!


Andrew Sinning Thu Jul 21 10:45:51 -0400 2011

Solved:

My problem was that in my class SettingType I was using "settingtotype" instead of "setting_to_type".

(1-1/1)