Model for ListData

I’m trying to get related data into a drop down list.

Here are my tables:

  1. PROJECTS: The project BELONGS_TO the customer.

  2. CUSTOMERS: The customer HAS_MANY contacts

  3. CONTACTS

I need a list of contacts to appear in my projects view

but I only need the ones that are related to the customer.

I can set up the projects view easy enough, its the contacts model I can’t seem to get.

This is where I’m at with it any help would be appreciated.


class Projects extends CActiveRecord

{ ...


public function relations()

	{

		return array(

		'Customer' => array(self::BELONGS_TO, 'Customers', 'CustomerID' ),

		'Contacts' => array(self:: <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />? ),

		);

	}

	

... }

Hi, Huss

Maybe you can use "HAS_MANY" with "through".

http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-through

I would create a new relation in Customers model with BELONGS_TO project relation, and use that to generate the dropdown

Thank you both.

It turned out to be simpler than I thought.

So long as a relationship exists from one model to the next.