Please read previous answer. I have to add however print("blah") in
constructor doesnt work, meaning the constructor is not initiated, but
getArrayResult returns expected result but getResult gives error! Why?
Isn't it because of constructor?
 در 2014 2 7 08:30، "Nima Sadjadi" <[email protected]> نوشت:

> As about recommendation in second part I highly appreciate them and will
> do so from now on but as about first part: No, I need OneToMany from
> Modules to ModulesConfig and the constructor also is in Modules. If so,
> then how the variables and constructor should be?
> در 2014 2 7 08:17، "Herman Peeren" <[email protected]> نوشت:
>
>> If you have a OneToMany relation from your ModulesConfig to your Modules,
>> do you mean: every Module has 1 ModuleConfig and a ModuleConfig can be part
>> of multiple Modules? Because then the $modules variable in ModulesConfig is
>> a collection. You now have it the other way around: you define a
>> $ModulesConfig collection in your Modules entity. Is there a $ModulesConfig
>> property (starting with a capital letter) in your Modules-entity?
>>
>> There are some conventions that are not obligatory, but I would strongly
>> advice you to keep to it (or otherwise: be aware of what standard you
>> follow):
>>
>>    - Class names shoud start with an uppercase character (also see
>>    PSR-1:
>>    
>> https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
>>    )
>>    - I always start properties (attributes) with a lowercase character,
>>    but there is no general recommendation for that.
>>    - ORM-specific: *A definition of an Entity is singular*. In your
>>    case: you would have a Module entity, not Module*s*. You define how
>>    one (1) Module-entity looks like.
>>    - *a collection is something in plural*. If you have a collection of
>>    Module-entities, I'd give it the name $modules. If you would have a
>>    collection of ModuleConfig-entities I'd give it the name $moduleConfigs.
>>    - I personally have my table names in plural (if I'm not using a
>>    legacy database). Giving an entity a plural name is probably some
>>    reminiscent of thinking in a Doctrine1 / Active Record / Tables way of
>>    doing things.
>>
>> The difficult thing with ORM is that it is in between the relational
>> database and the domain objects and hence you have to deal with two
>> different paradigms. Associations like OneToMany are stemming from the
>> Relational paradigm, while having an attribute that is a collection of
>> other entities is thinking in the Object paradigm. But those two are only
>> together in the mapping layer. In the rest of your application you can just
>> work with objects.
>>
>> So, please review your model, give it* proper names (entities in
>> singular, collections in plural)* and then apply your mapping. That will
>> solve your problem. BTW: if your "blah" is not printed, then the
>> constructor of your Modules entity is not called and hence no
>> Modules-entity was instantiated.
>>
>> *- Herman*
>>
>> On Friday, 7 February 2014 02:19:24 UTC+1, Parsifal wrote:
>>>
>>> I did set my Modules entity as OneToMany with my ModulesConfig entity
>>> and in my Modules entity I did set the constructor as below since this is
>>> OneToMany.
>>> I see both with and without this constructor it works fine, I even did
>>> use
>>> var_dump($this->ModulesConfig); and also print("blah") within
>>> constructor and nothing printed, am I doing some mistake in my class below?
>>> (However I don't get any error and it still works but curious to know.)
>>> class Modules {
>>>                public function __construct() {
>>>                        $this->ModulesConfig = new ArrayCollection();
>>>                        print("blah");
>>>                }
>>>                public static function loadMetadata(ClassMetadata
>>> $metadata) {
>>>
>>>
>>>
>>  --
>> 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.

Reply via email to