Hello.
I have a problem with composite primary key. I have 2 tables:
Company:
id_company (auto increment int) PK
company_name (varchar) Unique
CompaniesInCities:
country (varchar) PK
city (varchar) PK
company_name (varchar) PK
And I want to write this:
$myCompany = Company::model()->findByPk(1);
$city = $myCompany->getCity('google','usa')->city;
// $city = "Mountain View";
How should I design the relation? I need to join these two tables and manually specify columns country and company_name.
Each company can be in more cities and countries. Not twice in the same city.
class Company
{
public function relations()
{
relations()
{
'getCity'=>array(self::HAS_MANY, 'CompaniesInCities', 'Company(company_name,company_name)')
// this is probably incorrect <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />
}
}
}
Can any one help please, or paste usefull link?