Skip to content

Loading…

DDC-57: ManyToMany PDOException MySQL Syntax Error #5076

Closed
doctrinebot opened this Issue · 13 comments

1 participant

@doctrinebot

Jira issue originally created by user purnama:

For ManyToMany Relation I have an MySQL Sytax Error from the StandardEntityPersister.php

Hier is my error code:

2009-10-22T09:39:31+02:00 ERR (3): exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= lemmatype.type_id WHERE lemma_type.lemmaid = NULL' at line 1' in /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php:475
Stack trace:
#0 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Persisters/StandardEntityPersister.php(475): PDOStatement->execute(Array)
#1 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/Mapping/ManyToManyMapping.php(186): Doctrine\ORM\Persisters\StandardEntityPersister->loadManyToManyCollection(Object(Doctrine\ORM\Mapping\ManyToManyMapping), Array, Object(Doctrine\ORM\PersistentCollection))
#2 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/PersistentCollection.php(233): Doctrine\ORM\Mapping\ManyToManyMapping->load(Object(kateglo\application\models\Lemma), Object(Doctrine\ORM\PersistentCollection), Object(Doctrine\ORM\EntityManager))
#3 /usr/local/zend/apache2/htdocs/doctrine/lib/Doctrine/ORM/PersistentCollection.php(495): Doctrine\ORM\PersistentCollection->_initialize()
#4 /usr/local/zend/apache2/htdocs/kateglo/application/views/scripts/search/index.phtml(24): Doctrine\ORM\PersistentCollection->getIterator()

@roman: i send you the new database structure and the php code (models etc..)

@doctrinebot

Comment created by purnama:

This is the SQL statement produce by
$this->_getSelectManyToManyEntityCollectionSql($assoc, $criteria)

on line 474:

SELECT typeid, type_name, type_abbreviation FROM type INNER JOIN lemma_type ON type. = lemma_type.type_id WHERE lemma_type.lemmaid = NULL;

as you can see the syntax after ON is failure its type. with dot.

@doctrinebot

Comment created by purnama:

Hallo,

I try to fix this issue myself. i send you the patch code right after this.

for the info. i change my manytomany mapping like this

/****
* @var kateglo\application\helpers\collections\ArrayCollection
* @ManyToMany(targetEntity="kateglo\application\models\Lemma")
* @JoinTable(name="lemma_type",
* joinColumns={@JoinColumn(name="type_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="lemma_id", referencedColumnName="lemma")}
* )
*/

as you cann see the referencedColumnName did not referenced to column name in the database, but the member variable of the Entity class. or something like that. i dont understand :) but this is incosequent. maybe on later fix.. but i go on with this right now.

@doctrinebot

Comment created by romanb:

This should be fixed now in trunk. If not, please reopen this issue with new information. Thanks for reporting!

@doctrinebot

Comment created by purnama:

Hello,

Thank You for the patch.

But its still not functioning. I think you need to see my patch file that is attached to this issue.

There is two other problems that to be fix on many to many. the first one is ambigous table name problem (my relation table have the same column name as his parent table for foreign key.

the secod problem is the referencedColumnId name must be a class name or something.

only if i do this patch i can go on.

please take a look.

regards,
Arthur

@doctrinebot

Comment created by romanb:

Just to be sure, did you revert your local changes, using only the original latest code from trunk and changing back your annotations to the "right way" (column names)?

Like I said, I reproduced the issue in our tests and fixed it. I am no longer able to reproduce it.

Please add a new, failing test here: http://trac.doctrine-project.org/browser/trunk/tests/Doctrine/Tests/ORM/Functional/AdvancedAssociationTest.php

Add missing models, if necessary, and then attach a diff to this ticket.

Thanks!

@doctrinebot

Comment created by romanb:

I think I see the issue with the ambigious table name but the other problem should be fixed already.

@doctrinebot

Comment created by romanb:

I'm working on it and will get back to you shortly.

Thanks for your patience.

@doctrinebot

Comment created by romanb:

Please try the latest code from trunk now and report back. Thanks!

@doctrinebot

Comment created by purnama:

Hello,

Hier i send you a patch file for testing the ManyToMany problem. i hope this help.
I see that you already working on that.

Thank you very much.

@doctrinebot

Comment created by purnama:

Ok it works,

Thank You.

@doctrinebot

Comment created by romanb:

I added your new test to our suite! Thank you!

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-ALPHA3 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.