Hi Everyone,
I’ve been jumping into the Yii framework for a week or two now. All of the demos/tutorials seem to rely on the RDBMS supporting FK Constraints.
My setup includes a MySQL Cluster DB installation and a LAMP stack + Zend Server.
The first thing on the list of things that the Cluster DB DOESN’T support is FKs.
So my question is, without the use of foreign keys / cascading query support, how would I go about setting up the relational aspects of an application? Simple example would be a country dropdown being populated from the database. The main table would hold the ID of the country, the country table would hold the PK ID and Country Name.
With some searching I found a simple way using the CHtml helper to populate this in the _form, so the dropdown works. It didn’t solve the problem of the ID showing up versus the actual name of the country anywhere else.
So after some more reading, it looks like in the Model, “relations” would be the item to use? I tried to implement a relation, but it isn’t really doing anything. Take for example, my AccountType relation:
public function relations()
{
return array(
'accountTypeId' => array(self::HAS_ONE, 'AccountType', 'id', 'together'=>false),
);
}
From what I’ve read, this should match up the AccountTypeID field in my main table, with the right row in the AccountType table… am I on the right track here? There are tons of examples of relations, but I don’t understand how to make them work.
Thanks!
Matt