The schema tool now doesn't add a foreign constraint when subclassess of... #440

Closed
wants to merge 2 commits into
from

Conversation

Projects
None yet
3 participants
@sroddy
Contributor

sroddy commented Sep 8, 2012

... a STI use the same field to map relations with entities of different classes

It seems that there are no particular side-effects in mapping different relationship using the same table column name in different subclasses of a STI hierarchy.
Eg. Tag superclass of BookTag (id, object_id, comment) and MovieTag (id, object_id, comment), so having two attributes $book and $movie mapped to the same object_id field with @joincolumn annotation

I wasn't sure about this so I tested to see if there were errors. And I was surprised that everything runs without any particular problem.
Moreover this is a really interesting (wanted? unwanted?) feature, very useful if you have huge tables that need to be joined with other table using the discriminator and object_id columns, or if you have some kind of logging class and you need to keep the table efficient and small. The only problem is that the schema generator always inserts a foreign column constraint (probably the last specified) when generating these kind of Entities.

This PR ensures that the foreign key is not added if there are at least two different classes mapped on the same field of a db table.

@stof

This comment has been minimized.

Show comment
Hide comment
@stof

stof Sep 8, 2012

Member

This needs tests

Member

stof commented Sep 8, 2012

This needs tests

Stefano Rodriguez added some commits Sep 8, 2012

Stefano Rodriguez
The schema tool now doesn't add a foreign constraint when subclassess…
… of a STI use the same field to map relations with entities of different classes
@sroddy

This comment has been minimized.

Show comment
Hide comment
@sroddy

sroddy Sep 8, 2012

Contributor

@stof the PR should be ready now.

Contributor

sroddy commented Sep 8, 2012

@stof the PR should be ready now.

@sroddy

This comment has been minimized.

Show comment
Hide comment
@sroddy

sroddy Sep 13, 2012

Contributor

@beberlei @guilhermeblanco what do you think about this?

Contributor

sroddy commented Sep 13, 2012

@beberlei @guilhermeblanco what do you think about this?

beberlei added a commit that referenced this pull request Nov 12, 2012

@beberlei

This comment has been minimized.

Show comment
Hide comment
@beberlei

beberlei Nov 12, 2012

Member

Merged into master.

Member

beberlei commented Nov 12, 2012

Merged into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment