A vest in one table pair instance_id, instance_type in Doctrine


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/code-flow.club/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
4 views
Hello,

stolknulsya with issue in doctrine.

Imagine there are three basic table — participant, team, region.
One, let called log in which are stored the identical structure data — rank, points, position and so on for each object of the first table.

You must make at instance_id and instance_type can be bound two tables — log and some of the major, depending on the instance_type.

At first glance it's pretty simple, but after he described via a normal Doctrine_Query::create() and leftJoin, or through Doctrine_RawQuery::create() error that it is not possible to conduct a "hydrated." because the Log object is no connection, for instance.

If someone was stykalsya with such difficulty, can you please tell me the solution.
by | 4 views

2 Answers

0 like 0 dislike
Use Doctrine ODM + MongoDB :)
\r
If you do not fit this option, consider creating a common PrimaryKey (maybe some more fields will be common) for instance, that is, instead of instance_id and instance_type log is stored inctance_id, but it is common for the two tables and the linkage occurs either directly through him (then you have to ensure the uniqueness of id in both tables, a simple auto-increment will not work), or you can create another table with fields id (auto-increment, in which communication goes from the log), instance1_id, instance2_id + other common fields. In General, the pattern of "inheritance tables for each class" (if not confused).
\r
Once tried to solve a similar problem, but I have a number of types were unlimited and one SQL was not able to solve it
by
0 like 0 dislike
Why not add a link as the Doctrine?
\r
participant hasMany log
team hasMany log
region hasMany log
\r
communication on the field (instance_id -> id)
And in the query add the condition for the instance_type and target model.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
22,674 users