php - Access to many-to-many relation in array format, symfony2 -
in symfony can access many-to-many relations getter functions homecoming objects of arraycollection type. illustration getting alex's students can phone call $alex->getstudens()
, have access ale's studens object.
now question how can access alex's students id's in array, illustration calling $alex->getstudentsids()
returns {1,5,7,12,..} , students's ids.
precisely how wrote it, add together function in entity
public function getstudentsids() { $students = $this->students; $studentids = []; foreach($students $student) { $studentids[] = $student->getid(); } homecoming $studentids; }
ideal solution add together such method repository , have query pupil ids given object simpliest solution possible.
php symfony2 doctrine2 dql
No comments:
Post a Comment