nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
309 stars 59 forks source link

Idle in transaction #133

Closed f3l1x closed 9 years ago

f3l1x commented 9 years ago

I have a table similar to tag_followers.

This is same SQL:

CREATE TABLE "tag_followers" (
    "tag_id" int NOT NULL,
    "author_id"  int NOT NULL,
    "created_at"  timestamp NOT NULL,
    CONSTRAINT "tag_followers_tag_id_author_id" UNIQUE ("tag_id", "author_id"),
    CONSTRAINT "tag_followers_tag" FOREIGN KEY ("tag_id") REFERENCES "tags" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
    CONSTRAINT "tag_followers_author" FOREIGN KEY ("author_id") REFERENCES "authors" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

This table has no PRIMARY KEY, but only UNIQUE KEY.

Orm can not save this entity and process is idle in transaction. It was very difficult to find it. I don't know if it is a bug or right behaviour.

If it is oukey, some warning / trigger error would be nice.

What do you think?

hrach commented 9 years ago

Ok, primary key is compulsory, so Orm should throw an exception, if none is defined.

hrach commented 9 years ago

Orm already throws an exception. https://github.com/nextras/orm/blob/25ac237069852dd197ecdeb184c702bf609537e9/src/Mapper/Dbal/StorageReflection/StorageReflection.php#L81-L84 Otherwise, please provide some example which causes the problem. Also, I don't understand what does it mean that process is idle in transaction. The work "oukey" is weird too.

f3l1x commented 8 years ago

@hrach Can I ask you, why is forced to have to a primary key/s at storage?

hrach commented 8 years ago

To be able to uniquely identity a row