Can DBAL be mixed with ORM Query Builder?

I am trying to create a query builder using ORM. But I come across a field on entities with relation to two possible tables. With this structure it would be (IMHO) impossible to match it in the entity itself.

╔═══════╗ ╔═══════╗ ╔═══════╗ β•‘ ValB β•‘ β•‘ Main β•‘ β•‘ ValC β•‘ ╠══╦════╣ ╠══╦════╣ ╠══╦════╣ β•‘ *β•‘ pk β•‘-- + β•‘ *β•‘ pk β•‘ +---β•‘ *β•‘ pk β•‘ ╠══╬════╣ | ╠══╬════╣ | ╠══╬════╣ β•‘ β•‘ β•‘ +--β•‘ β•‘v_idβ•‘---+ β•‘ β•‘ β•‘ ╠══╬════╣ ╠══╬════╣ ╠══╬════╣ β•‘ β•‘ β•‘ β•‘ β•‘ β•‘ β•‘ β•‘ β•‘ β•šβ•β•β•©β•β•β•β•β• β•šβ•β•β•©β•β•β•β•β• β•šβ•β•β•©β•β•β•β•β• 

Is it possible to mix DBAL QueryBuilder with ORM QueryBuilder or in any other way that will still use ORM QueryBuilder mainly in code.

PS. I did not design db and im just optimizing it. sorry for that: (

+5
source share
1 answer

No, this does not make sense, because later the ORM should map the results to objects. You cannot match both ValB and ValC with the same property in Main

To do this correctly, the Main table must have separate fields for the ValB and ValC . Even if they have the same meaning. Like this

 ╔═══════╗ ╔════════╗ ╔═══════╗ β•‘ ValB β•‘ β•‘ Main β•‘ β•‘ ValC β•‘ ╠══╦════╣ ╠══╦═════╣ ╠══╦════╣ β•‘ *β•‘ pk β•‘-- + β•‘ *β•‘ pk β•‘ +---β•‘ *β•‘ pk β•‘ ╠══╬════╣ | ╠══╬═════╣ | ╠══╬════╣ β•‘ β•‘ β•‘ +--β•‘ β•‘vB_idβ•‘ | β•‘ β•‘ β•‘ ╠══╬════╣ ╠══╬═════╣ | ╠══╬════╣ β•‘ β•‘ β•‘ β•‘ β•‘vC_idβ•‘---+ β•‘ β•‘ β•‘ β•šβ•β•β•©β•β•β•β•β• β•šβ•β•β•©β•β•β•β•β•β• β•šβ•β•β•©β•β•β•β•β• 

You can copy the v_id column and then do the correct mapping in Doctrine.

+5
source

All Articles