Yii Framework Forum: Yii + MySQL Cluster DB, How to get around FK Constraints? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii + MySQL Cluster DB, How to get around FK Constraints? Rate Topic: -----

#1 User is offline   mbabineau 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-June 11
  • Location:San Diego, CA

Posted 25 October 2011 - 11:41 AM

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
0

#2 User is offline   mbabineau 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 07-June 11
  • Location:San Diego, CA

Posted 25 October 2011 - 03:12 PM

Just an update on this:

I was able to get the relations working right for the situation of the dropdown (id / value) and linking the main table to a sub-table.

I just needed to modify the relation to be "BELONGS_TO". Now, an object exists called account_type in the views:


	public function relations()
	{
		return array(
			'account_type' => array(self::BELONGS_TO, 'AccountType', 'id', 'together'=>false),
		);
	}



So, in the list view, I can echo $data->account_type->accountType and it will output the correct name for the ID that was set.

Next, I'll see if I can CRUD against 2 linked tables, 1-to-1.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users