Doctrine 1.2: How can I prohibit one-to-many opposition to both sides?

Is there a way to prevent the Doctrine from assigning a one-to-one relationship on both sides? Ive tried to move the definition from one side to the other and use its own side, but still puts a restriction on both tables. when I want the parent table to have a constraint - that is. its possible for a parent to not have an associated child.

For example, the following sql schema is essentially:

CREATE TABLE `parent_table` (
  `child_id` varchar(50) NOT NULL,
  `id` integer UNSIGNED NOT NULL auto_increment,
  PRIMARY KEY (`id`)
);

CREATE TABLE `child_table` (
  `id` integer UNSIGNED NOT NULL auto_increment,
  `child_id` varchar(50) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY (`child_id`),
  CONSTRAINT `parent_table_child_id_FK_child_table_child_id`
    FOREIGN KEY (`child_id`)
    REFERENCES `parent_table` (`child_id`)
);

However, I get something like this:

CREATE TABLE `parent_table` (
  `child_id` varchar(50) NOT NULL,
  `id` integer UNSIGNED NOT NULL auto_increment,
  PRIMARY KEY (`id`),
  CONSTRAINT `child_table_child_id_FK_parent_table_child_id`
    FOREIGN KEY (`child_id`)
    REFERENCES `child_table` (`child_id`)
);

CREATE TABLE `child_table` (
  `id` integer UNSIGNED NOT NULL auto_increment,
  `child_id` varchar(50) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY (`child_id`),
  CONSTRAINT `parent_table_child_id_FK_child_table_child_id`
    FOREIGN KEY (`child_id`)
    REFERENCES `parent_table` (`child_id`)
);

, / ( " " ), , , .

Symfony 1.4.4 (Pear installtion ATM) - sfDoctrinePlugin Doctrine.

-1
2

sfDoctrinePlugin , . PHP 5.2 .

PHP 5.3, ReflectionProperty::setAccessible() , / Doctrine_Relation_Parser, $this->getTable()->getRelationParser(). , BaseSomething::setUp() , API- php. API , Doctrine_Relation_Parser , .

+2

, " " , :

/* @var $address Address */
$address = $form->getObject();

// the null object is here the "address position", let change it state
$address->getAddressPosition()->state(Doctrine_Record::STATE_CLEAN);

// now we can save the address and doctrine won't insert the null object
$address = $form->save();
+1

Source: https://habr.com/ru/post/1767857/


All Articles