I have a problem with single table inheritance, and I'm not sure if I interpret the documentation correctly.
First: I did not copy my code / entity mappings verbose (or even using the correct syntax) here, since I think the problem could be better conveyed abstractly. If this is unacceptable, say so, and I will add the full code, but it MUST, and I think that my question can be answered without it.
If this helps, I can make an ER chart to try and let me know what I'm trying to do. If you read the following and think “hey what should work” - tell me and I will download the real code
Second: I do not use lazy loading anywhere. Before contacting my entities, I make sure that I load every related object that I am going to access by writing DQL in front, so the following problem is pretty terminal for my application)
Setup:
I have several objects - they make up the core of my application.
// @entity AnimalTrainingSchool
// oneToMany: trainingDepartment
fields: [name / location / year founded]
// @entity trainingDepartment
oneToMany: animalTrainer
oneToOne: building
fields: [capacity]
// @entity animalTrainer
fields: [name / age / qualification]
I refer to them often and in different contexts - but I usually repeat the access levels and properties and relationships for these objects.
foreach ($animalTrainingSchool as $school){
echo $school->getName() . ' at ' . $school->getLocation();
echo 'These are the training departments for this school:';
foreach ($school->getTrainingDepartments as $trainingDepartment){
echo $trainingDepartment->getAnimalTypeTrained() . ' are trained in this department';
}
}
I am sure that they are all loaded in front, having formed my DQL and executed it - in order to limit the number of SQL queries (to one). All this works fine (pretty standard stuff).
DQL Example : "SELECT ats, td, at FROM AnimalTrainingSchool ats JOIN AnimalTrainingSchool.trainingDepartments td JOIN td.animalTrainer at";
This sets up my collection and means that I can cross it without requiring additional requests.
Problem:
- (. MAJOR (. )
2
{id information / table information / discriminator map / inheritance type (SINGLE_TABLE)}
fields: [medalMaterial / award_serial_number]
oneToOne: trainingDepartment
oneToOne: animalTrainer
,
// @entity trainingDepartment
oneToMany: animalTrainer
oneToOne: building
oneToOne: departmentAward
fields: [capacity]
// @entity animalTrainer
fields: [name / age / qualification]
oneToOne: trainerAward
, , , () , .
, , Departments/AnimalTrainers Doctrine SQL .
20 10 - 200 .
//Given the exact same DQL and foreach loop as above (note that at no stage am I accessing awards) - I get a ton of extra queries that look like this
"SELECT award.property1, award.property2, award.property3 FROM awardTable LEFT JOIN trainingDepartmentTable ON award.awardee_id = trainingDepartmentTable.id and award.discriminatorColumn IN ('departmentAward')";
// or...
"SELECT award.property1, award.property2, award.property3 FROM awardTable LEFT JOIN animalTrainerTable ON award.awardee_id = animalTrainerTable.id and award.discriminatorColumn IN ('trainerAward')";
, , - , , , , ( @Matthieu, - 3 LOWEST
"award", , , .
Stackoverflow , ,
2
http://www.doctrine-project.org/docs/orm/2.0/en/reference/inheritance-mapping.html#performance-impact
: STI "--" "--" "targetEntity", , . .
, , - Doctrine .
: , , , , . .