Ok, sorry, I can't withstand: http://lmgtfy.com/?q=doctrine+entity+constructor
and: http://docs.doctrine-project.org/en/latest/reference/architecture.html#entities, states: The constructor of an entity is only ever invoked when *you* construct a new instance with the *new* keyword. Doctrine never calls entity constructors, thus you are free to use them as you wish and even have it require arguments of any type. Please, a lot of people (myself included), spend quite some time to read the documentation (written by volunteers, respect it). Yes, it is a lot and it might take some hours / days, but is seems you are persistent enough to not quit before you got what you want ;). So before posting a question again, count to 100 out loud! Cheers! On 7 February 2014 22:19, Menno Holtkamp <[email protected]> wrote: > This might have something to do with the Entity proxy intercepting the > initialization (in combination with lazy loading?). I believe Marco Piveta > AKA Ocramius wrote a lot about the subject. Google for it and/or dive in > the source code. > > But, you can also trust on the force to always be with you, right? > > Cheers > On Feb 7, 2014 9:35 PM, "Nima Sadjadi" <[email protected]> wrote: > >> Herman, >> Here is the info you asked me this morning, correcting uppercase >> things etc. it returns expected data the only odd thing is that >> print("blah") in constructor is not working so the this is not called >> but still works! any idea? >> >> <?php >> // Modules.php >> namespace Entities; >> use Doctrine\ORM\Mapping\ClassMetadata; >> use Doctrine\ORM\Mapping\ClassMetadataInfo; >> use Doctrine\Common\Collections\ArrayCollection; >> class Modules { >> private $module; >> private $status; >> private $modulesConfig; >> public function __construct() { >> $this->modulesConfig = new ArrayCollection(); >> print("a"); >> var_dump($this->modulesConfig); >> } >> public static function loadMetadata(ClassMetadata $metadata) { >> // here goes $metadata->mapField array I did generate with CLI >> // coloumns in this table: module, status >> // join coloumns with that other table: module=>module >> $metadata->mapOneToMany(array( 'fieldName' => 'modulesConfig', >> 'targetEntity' => 'Entities\\ModulesConfig', >> 'mappedBy' => 'modules', >> 'joinColumns' => array( 0 => array( >> 'name' => 'module', >> >> 'referencedColumnName' => 'module', >> >> 'nullable' => true, >> >> 'columnDefinition' => NULL, >> ), ) >> >> )); >> } >> } >> == >> <?php >> // ModulesConfig.php >> namespace Entities; >> use Doctrine\ORM\Mapping\ClassMetadata; >> use Doctrine\ORM\Mapping\ClassMetadataInfo; >> class ModulesConfig { >> private $id; >> private $module; >> private $variable; >> private $value; >> private $modules; >> public static function loadMetadata(ClassMetadata $metadata) { >> // here goes $metadata->mapField array I did generate with CLI >> // coloumn in this table: id, module, variable, value >> // join coloumns with that other table: module=>module >> >> $metadata->mapManyToOne(array( 'fieldName' => 'modules', >> 'targetEntity' => 'Entities\\Modules', >> 'inversedBy' => 'modulesConfig', >> 'joinColumns' => array( 0 => array( >> 'name' => 'module', >> >> 'referencedColumnName' => 'module', >> >> 'nullable' => true, >> >> 'columnDefinition' => NULL, >> ), ) >> >> )); >> } >> } >> >> >> >> >> On Fri, Feb 7, 2014 at 1:38 PM, Herman Peeren <[email protected]> >> wrote: >> > No idea what you are doing wrong without the code of the 2 entities >> plus the >> > calling code, query etc. >> > >> > On Friday, 7 February 2014 10:34:08 UTC+1, Parsifal wrote: >> >> >> >> In two cases below you described, the first case is the one I actually >> >> want to. And actually it is working fine with expected result. The >> only odd >> >> thing is that print("blah") in constructor doesn't print so I assume >> the >> >> constructor is not working however I am still getting correct result! >> Second >> >> odd thing is that only getArrayResult returns something for this but I >> get >> >> error for getResult. Let's look at second problem later but first let's >> >> check why constructor is not working however I am still getting correct >> >> result?! Any idea? >> >> >> >> 1) In a Module-entity you can have multiple ModuleConfig-entities and >> >> every ModuleConfig-entity only has 1 Module. In this case you'll have a >> >> $moduleConfigs collection in a Module on which a >> OneToMany-relationship is >> >> defined. In a ModuleConfig you then have a $module defined with a >> ManyToOne >> >> relation. >> >> 2) Or: in a Module-entity you can only have 1 ModuleConfig-entity, but >> a >> >> ModuleConfig-entity can be associated with multiple Module-entities. >> In >> >> that case you'll have a $moduleConfig propery in a Module on which a >> >> ManyToOne-relationship is defined. In a ModuleConfig you then have a >> >> $modules collection defined with a OneToMany relation. >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "doctrine-user" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> an >> > email to [email protected]. >> > To post to this group, send email to [email protected]. >> > Visit this group at http://groups.google.com/group/doctrine-user. >> > For more options, visit https://groups.google.com/groups/opt_out. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "doctrine-user" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/doctrine-user. >> For more options, visit https://groups.google.com/groups/opt_out. >> > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/groups/opt_out.
