Hi Andrew.
Was just wondering if you solved your issue and if so how.
I have a similar issue with plurals, sort of.
My set-up consists of 3 tables: restaurant, category and restaurantcategory. Restaurant may fall under one or more categories, and each category may have many restaurants.
So in the Restaurant class I have:
static $has_many = array(
array('restaurantcategorys'),
array('category', 'through' => 'restaurantcategorys')
);
In the Category class I have:
static $has_many = array(
array('restaurantcategorys'),
array('restaurants', 'through' => 'restaurantcategorys')
);
And this works perfectly.
But having "categorys" (as opposed to "categories") in my code really bugs me. Silly I know, but... Hence my dilemma on how to use (properly spelled) plurals in this context.
Any ideas?
Thanks.
Les,
I can't say that I've "solved" anything with respect to naming conventions. I remain mystified. I suspect that some of my confusion and difficulty debugging is related to the way php activerecord caches classes. I will start a separate thread. Hopefully someone will follow up.
Les,
Your tables should be called categories, restaurant_categories, and restaurants and your models should look like:
1 <? 2 class Restaurant extends ActiveRecord\Model { 3 static $has_many = array( 4 array('restaurant_categories'), 5 array('categories, 'through' => 'restaurant_categories') 6 ); 7 } 8 9 class Category extends ActiveRecord\Model { 10 static $has_many = array( 11 array('restaurant_categories'), 12 array('restaurants', 'through' => 'restaurant_categories') 13 ); 14 } 15
The pluralization changes based on what type of relationship you are building. A has_many relationship is pluralized while a belongs_to or has_one is singular.
static $belongs_to = array( array('person') );
static $has_many = array( array('persons'));
static $has_one = array( array('person') );
(1-3/3)
Subject: please help me understand when/where to put the plural
I have a class called "QuizUser".
I can reference and successfully retrieve data from it using ANY of the following four has_many associations in another class:
So much flexibility. Shouldn't there be a rule? Does the naming convention have anything to do with whether the relationship is belongs_to, has_one or has_many?
Thanks!