php - Get only list of ID's from ManyToMany with Doctrine -
i have manytomany associated field, , i'm in situation i'm trying id's without hydrating of sub-entities in field.
i understand there query aquire entity references moment access field, , that's fine/expected. need loop through id's, don't quite know how them without doing
$ids = []; foreach($mainentity->getsubentities() $subentity) { $ids[] = $subentity->getid(); }
this seems hydrate sub entity automatically, im assuming because of foreach
loop. results in lot of unnecessary queries , impacts page load time.
i have subentity field marked extralazy
well.
/** * @var arraycollection * @orm\manytomany(targetentity="user", fetch="extra_lazy") * @orm\jointable(name="user_friends") */ protected $friends;
doctrine's arraycollection
class provides method called: getkeys()
.
using can create new method extract ids collection follows:
public function getfriendids() { return $this->friends->getkeys(); }
doctrine map entity primary key collection key unless otherwise specified. solve you're problem.
Comments
Post a Comment