doctrine2 - Symfony - Get Entity from within another entity -
i retrieve record entity (or record db) within entity.
they there no relationship between 2 entities.
i using @orm\haslifecyclecallbacks()
, @orm\prepersist
when main entity created create entity (save record table)
the above working fine, there no issues this.
what having issue link entity table need retrieve object based on value of first entity.
usually write function in entity repository not calling entity manager within entity.
an entity in doctrine object representation of concept, attributes , methods. meant lightweight, popo (plain old php object). must not know persistence. therefore if see reference entitymanager
in model, stinks.
solutions? use entity listener called on entity creation , use service dedicated compose object(s), maybe factory. in way, entity stays lightweight, lifecycle management satisfied , entity composing responsibility of service.
Comments
Post a Comment