ssin
ssin

Reputation: 221

zend framework table relationships, referenceMap & dependentTables

I'm new to zend framework, i'm trying to understand how table relationships work. I have two tables and i'm trying to link them and get their data in a list.

CREATE TABLE  `relationship` (
  `relationship_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `relationship_name` varchar(45) NOT NULL,
  `relationship_group_id` int(10) unsigned NOT NULL,
  `display` int(10) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`relationship_id`),
   KEY `FK_relationship_1` (`relationship_group_id`),
  CONSTRAINT `FK_relationship_1` FOREIGN KEY (`relationship_group_id`) REFERENCES     `relationship_group` (`relationship_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE  `relationship_group` (
  `relationship_group_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `relationship_group_name` varchar(45) NOT NULL,
  `display` int(10) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`relationship_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

In my relationship table class, I have:

class Relationship_Table extends Zend_Db_Table_Abstract
{
    protected $_rowClass = 'Relationship';
    protected $_name = 'relationship';

In my relationship group table class I have:

class Relationship_Group_Table extends Zend_Db_Table_Abstract
{
protected $_name = 'relationship_group';
protected $_rowClass = ' Relationship_Group';

I am not sure what my $_referenceMap and $_dependentTables should say, and if I need to state them in both classes or just one?

Also how do I get a list from my relationships table with the corresponding relationship_group data included.

Any help is appreciated.

Upvotes: 0

Views: 3357

Answers (2)

maryl
maryl

Reputation: 456

$_dependentTables aren't required in your case (using InnonDB).

Zend References

Note: Skip declaration of $_dependentTables if you use referential integrity constraints in the RDBMS server to implement cascading operations

Your $_referenceMap should link FOREIGN KEY in a dependent table to the PRIMARY KEY in the parent table and it's only required in the dependent table.

The rest is as RockyFord suggested in his link :).

Upvotes: 0

RockyFord
RockyFord

Reputation: 8519

Here is a pretty good primer on table relationships.
Mat McCormisck on Table relationships in Zend Framework

The actual answer to your question is:

  • It depends on what you need to accomplish and how do you want to accomplish it.

Upvotes: 2

Related Questions