DDC-3476: JoinTable options are not inherited #4282

Open
opened 2026-01-22 14:38:42 +01:00 by admin · 1 comment
Owner

Originally created by @doctrinebot on GitHub (Jan 6, 2015).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user eschultz:

I'm working with Symfony 2.6 and Doctrine (MySQL), but the error is in the Doctrine 2 ORM.

I have specified a ManyToMany relation like so:

/****
 *@ORM\Table(name="users", options={"engine"="MyISAM", "collate"="utf8*general*ci"})
 * @ORM\Entity
 */
class User
{
  /****
    * @ORM\ManyToMany(targetEntity="Group", inversedBy="users")
    * @ORM\JoinTable(name="user*groups", joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, inverseJoinColumns={@ORM\JoinColumn(name="group*id", referencedColumnName="id")})
  */
  private $groups;

...
}

All tables should be created as MyISAM and "utf8_general_ci" collation instead of InnoDB and "utf8_unicode_ci". This works fine for all tables except for "user_groups" table because the options are not inherited. As a result the schema is not valid, because foreign keys cannot be created over 2 different collations.

To fix this, I modified class "\Doctrine\ORM\Tools\SchemaTool", function "gatherRelationsSql($class, $table, $schema, &$addedFks, &$blacklistedFks)" and added the following lines in the MANY_TO_MANY block:

if (isset($foreignClass->table['options'])) {
  foreach ($foreignClass->table['options'] as $key => $val) {
    $theJoinTable->addOption($key, $val);
  }
}

Now, it works as I want. The new table is created with the right collation and engine and the foreign keys are created correct. Could you please implement this fix?

Originally created by @doctrinebot on GitHub (Jan 6, 2015). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user eschultz: I'm working with Symfony 2.6 and Doctrine (MySQL), but the error is in the Doctrine 2 ORM. I have specified a ManyToMany relation like so: ``` /**** *@ORM\Table(name="users", options={"engine"="MyISAM", "collate"="utf8*general*ci"}) * @ORM\Entity */ class User { /**** * @ORM\ManyToMany(targetEntity="Group", inversedBy="users") * @ORM\JoinTable(name="user*groups", joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, inverseJoinColumns={@ORM\JoinColumn(name="group*id", referencedColumnName="id")}) */ private $groups; ... } ``` All tables should be created as MyISAM and "utf8_general_ci" collation instead of InnoDB and "utf8_unicode_ci". This works fine for all tables except for "user_groups" table because the options are not inherited. As a result the schema is not valid, because foreign keys cannot be created over 2 different collations. To fix this, I modified class "\Doctrine\ORM\Tools\SchemaTool", function "gatherRelationsSql($class, $table, $schema, &$addedFks, &$blacklistedFks)" and added the following lines in the MANY_TO_MANY block: ``` if (isset($foreignClass->table['options'])) { foreach ($foreignClass->table['options'] as $key => $val) { $theJoinTable->addOption($key, $val); } } ``` Now, it works as I want. The new table is created with the right collation and engine and the foreign keys are created correct. Could you please implement this fix?
admin added the Bug label 2026-01-22 14:38:42 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 6, 2015):

Comment created by eschultz:

Please also have a look at DDC-972 where MyISAM support was added. The problem was already mentioned there in the last 4 comments, so it exists at least since 2012.

@doctrinebot commented on GitHub (Jan 6, 2015): Comment created by eschultz: Please also have a look at [DDC-972](http://www.doctrine-project.org/jira/browse/DDC-972) where MyISAM support was added. The problem was already mentioned there in the last 4 comments, so it exists at least since 2012.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4282