mysql - Joins symfony 2 -
i have 3 tables , use yaml, connect each other this:
trainings:
onetomany: exercisetrainings: targetentity: exercisetraining mappedby: training cascade: ["persist", "merge"] joincolumn: name: id referencedcolumnname: training_id
exercises:
onetomany: exercisetrainings: targetentity: exercisetraining mappedby: exercise cascade: ["persist", "merge"] joincolumn: name: id referencedcolumnname: exercise_id
trainingexercises:
manytoone: exercise: targetentity: exercise inversedby: exercisetrainings joincolumn: name: exercise_id referencedcolumnname: id training: targetentity: training inversedby: exercisetrainings joincolumn: name: training_id referencedcolumnname: id
i need "exercise name" table exercises(basically name coming exercise_translation, think it's not problem) related trainings , need "sets" exercisetrainings table. have training , try join tables:
$training = $em->getrepository('trenkatrainingbundle:training')->findonebyalias($alias); $exercises = $em ->getrepository('trenkatrainingbundle:exercise') ->createquerybuilder('e') ->innerjoin('e.exercisetrainings', 't') ->where('t.training_id = ' . $training->getid()) ->getquery() ->getresult();
but error:
class trainingbundle\entity\exercisetraining has no field or association named training_id
maybe has same structures , know how make work? how presented values 2-3 tables in twig?
you doesn't have training_id field in exercisetraining entity can't use in clause, in exercisetraining entity have training field can try :
$exercises = $em ->getrepository('trenkatrainingbundle:exercise') ->createquerybuilder('e') ->innerjoin('e.exercisetrainings', 'et') ->where('et.training = :training') ->setparameter('training', $training) ->getquery() ->getresult();
Comments
Post a Comment