symfony / symfony/maker-bundle
Bad @JoinColumn when foreign id column isn't named 'id'
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.4k
- Forks
- 427
- Avg merge
- 2d 22h
- Merged PRs (30d)
- 20
Description
I've got an entity named Brand, with
- an Id attribute, Primary key, base on a column named 'idMarque' (It's a legacy table I have to deal with for now)
- an ExternalId attribute, mapped to a columnd named "ID"
I create a new entity, BrandUrl, with a ManyToOne to Brand
The "JoinColumn" don't refer to the column name of the PK of the foreign entity.
It should explicit @ORMJoinColumn(referencedColumnName="idMarque", ...)
Edited - following is true if you don't correct the JoinColumn. Did'nt try recreating the migration after having corrected it.
When I do make:migration, the maker generates
ALTER TABLE brand_url ADD CONSTRAINT FK_913D50DF44F5D008 FOREIGN KEY (brand_id) REFERENCES previous_marques (id)
It should reference the idMarque column.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the make:migration output for a Brand entity whose primary key is idMarque and a BrandUrl ManyToOne association. Trace how the migration derives the foreign-key reference and verify that the generated constraint points to idMarque rather than id. Done means the migration references the legacy primary-key column correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100