Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.2.0-ALPHA1, 1.2.0-ALPHA2, 1.2.0-ALPHA3, 1.2.0-BETA1, 1.2.0-BETA2, 1.2.0-BETA3, 1.2.0-RC1, 1.2.0, 1.2.1, 1.2.2
-
Fix Version/s: None
-
Component/s: Import/Export, Relations
-
Labels:None
-
Environment:i tried both under linux / win; with doctrine 1.1 / 1.2.1
tried with sandbox / direct creating "bootstrap" => same results...
Description
it seems that the naming is important:
in a User, Group, UserGroup relation (where the UserGroup defines the many to many relation for User & Group) the constraints are defined well
but if the tables are Order, Service, OrderService it doesn't work => just one constraint is created... please find my example:
Order:
tableName: orders
columns:
name: string(50)
relations:
Services:
class: Service
local: order_id
foreign: service_id
refClass: OrderService
Service:
actAs:
Versionable: ~
columns:
name: string(50)
relations:
Orders:
class: Order
local: service_id
foreign: order_id
refClass: OrderService
# WTF: it takes alphbetically the constraints building !?
# if I used ZorderService instead of OrderService, Z is after S (O is before S) the constraints are defined fine!
OrderService:
columns:
order_id: { type: integer, primary: true }
service_id: { type: integer, primary: true }
==> the generated SQL
CREATE TABLE orders (id BIGINT AUTO_INCREMENT, name VARCHAR(50), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE order_service (order_id BIGINT, service_id BIGINT, version BIGINT, PRIMARY KEY(order_id, service_id,
version)) ENGINE = INNODB;
CREATE TABLE service_version (id BIGINT, name VARCHAR(50), version BIGINT, PRIMARY KEY(id, version)) ENGINE =
INNODB;
CREATE TABLE service (id BIGINT AUTO_INCREMENT, name VARCHAR(50), version BIGINT, PRIMARY KEY(id)) ENGINE =
INNODB;
ALTER TABLE order_service ADD CONSTRAINT order_service_order_id_orders_id FOREIGN KEY (order_id) REFERENCES
orders(id);
ALTER TABLE service_version ADD CONSTRAINT service_version_id_service_id FOREIGN KEY (id) REFERENCES service(id)
ON UPDATE CASCADE ON DELETE CASCADE;
=> as you can see for TABLE order_service just one constraint is defined (order_service_order_id_orders_id) the other one (order_service_service_id_service_id) is missing !!!
However if i change the names for tables (actually i think alphabetically order) and use ZorderService instead of OrderService (lik UserGroup for User & Group) the two constraints are created!
This also affects the "getRelations()" when i tried to write a behavior (it gives back just one relation):
foreach ($event->getInvoker()->getTable()->getRelations() as $relation)
ps:
also the same bug reported on the list: http://groups.google.com/group/doctrine-user/browse_thread/thread/ad48db71b71e043b
(edit G.X: split too long lines in SQL code)
I seem to have a very similar issue. It is really annoying because no error feedback is given at any point...
In my case, one out of three many-to-many relations actually has its constraints created, the other two not.
However, if I take the file date/sql/schema.sql (I am working with Symfony 1.4.4) and run as an SQL query directly with my database, the constraints are created properly!
So, with symfony, if I go:
$ symfony14 doctrine:build-model
$ symfony14 doctrine:build-sql
$ symfony14 doctrine:insert-sql
The model gets generated, the database gets generated, but several many-to-many constrains are missing.
Then if I go:
$ symfony14 doctrine:build-model
$ symfony14 doctrine:build-sql
$ mysql -u user -p database < date/sql/schema.sql
The model gets generated, the database gets generated, and the constraints are in place.
Hope this helps to have the problem fixed.
Cheers,
Piotrek