Andrew Sinning Fri Jul 15 10:42:53 -0400 2011

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:

static $has_many = array(
static $has_many = array(
static $has_many = array(
static $has_many = array(

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?


Les Carbonaro Sun Aug 07 04:04:44 -0400 2011

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('category', 'through' => 'restaurantcategorys')

In the Category class I have:
static $has_many = array(
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?


Andrew Sinning Mon Aug 08 11:11:45 -0400 2011


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.

Clay vanSchalkwijk Wed Sep 07 17:55:22 -0400 2011


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 }
 9 class Category extends ActiveRecord\Model {
10   static $has_many = array( 
11     array('restaurant_categories'), 
12     array('restaurants', 'through' => 'restaurant_categories') 
13   );
14 }

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') );