I am trying to create a querybuilder using ORM. But I stumble upon a field on an entity with a relationship to 2 possible tables. With this structure it would be (IMHO) impossible to map it in the entity itself.
╔═══════╗ ╔═══════╗ ╔═══════╗
║ ValB ║ ║ Main ║ ║ ValC ║
╠══╦════╣ ╠══╦════╣ ╠══╦════╣
║ *║ pk ║-- + ║ *║ pk ║ +---║ *║ pk ║
╠══╬════╣ | ╠══╬════╣ | ╠══╬════╣
║ ║ ║ +--║ ║v_id║---+ ║ ║ ║
╠══╬════╣ ╠══╬════╣ ╠══╬════╣
║ ║ ║ ║ ║ ║ ║ ║ ║
╚══╩════╝ ╚══╩════╝ ╚══╩════╝
Is is possible to mix DBAL QueryBuilder with ORM QueryBuilder, or any other way that will still use the ORM QueryBuilder mostly on the code.
PS. I did not design the db and im just optimizing it. sorry for this :(
No it doesn't make sense, because later ORM have to map results to objects. You can't map both ValB
and ValC
to the same property in Main
To do it correctly, there should be separate fields in Main
table for ValB
and ValC
relations. Even if they have the same value. Like this
╔═══════╗ ╔════════╗ ╔═══════╗
║ ValB ║ ║ Main ║ ║ ValC ║
╠══╦════╣ ╠══╦═════╣ ╠══╦════╣
║ *║ pk ║-- + ║ *║ pk ║ +---║ *║ pk ║
╠══╬════╣ | ╠══╬═════╣ | ╠══╬════╣
║ ║ ║ +--║ ║vB_id║ | ║ ║ ║
╠══╬════╣ ╠══╬═════╣ | ╠══╬════╣
║ ║ ║ ║ ║vC_id║---+ ║ ║ ║
╚══╩════╝ ╚══╩═════╝ ╚══╩════╝
You could copy v_id
column and then make proper mapping in Doctrine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With