Hi Nima:
1. when find() has no result it returns false, not null
2. when it is dfound (your else-clause) it is managed and you don't need
to call persist()
3. I'd go for the $client and do something with its $credit instead of
first going to the $credit and then adding that to a client, but many ways
lead to Rome.
4. never var_dump() Doctrine entities, use
Doctrine\Common\Util\Debug::dump()instead,
as mentioned in the alert in the documentation under
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html#adding-bug-and-user-entities
On Wednesday, 7 May 2014 00:33:40 UTC+2, Parsifal wrote:
>
>
> Herman,
> Do you remember while ago we had discussion about entity was not found
> error? I think I am near to catch it.
> Credit entity is OneToOne to Client entity, I want to first check if
> Credit entity exists, update it, if does not exist add it, so I did:
>
> $credit = $em->find('Entities\Credit', $client_id);
> if ($credit === null) {
> $client = $em->find('Entities\Client',
> $client_id);
> $credit = new Entities\Credit;
> $credit->setClient($client);
> // methods to set properties goes here.
> $em->persist($credit);
> } else {
> // methods to set properties goes here.
> $em->persist($credit);
> }
> If Credit entity exists, I get no problem, if does not exists, I get
> entity was not found eoor. With print() and exit; debugging I discovered,
> if there is no credit entity for that particular client, it doesn't care
> about if ($credit === null) { in my code, so it goes to /else/ code
> block, and obviously it does not find the entity! I appreciate your advice
> why it doesn't care about if ($credit === null) and how can I debug it? it
> seems does not recognize $credit as null? if yes, how can I debug it?
> var_dump gives a very very long object of almost all entities.... and I
> think this is impossible to find the problem with var_dump.
>
>
>
>
>
>
>
>
>
>
> On Mon, Apr 21, 2014 at 12:14 AM, Nima Sadjadi <[email protected]<javascript:>
> > wrote:
>
>>
>> No, just some ordinary fields I am trying to update, these fields are not
>> used as FK nor any of them is id. as stated on wiki I am using in_array for
>> security check too. but I did double-check that setFields method indeed
>> exists in Info entity. But I am not getting undefined method, I am getting
>> "entity was not find". any idea how to check/fix it?
>>
>>
>>
>>
>> On Sun, Apr 20, 2014 at 11:50 PM, Herman Peeren
>> <[email protected]<javascript:>
>> > wrote:
>>
>>> On Sunday, 20 April 2014 21:04:45 UTC+2, Parsifal wrote:
>>>
>>>> please read my previous answer. since I am not getting an order for
>>>> ->getInfo() should I assume that my info entity is loaded? if yes, then
>>>> why
>>>> should I get "entity was not found error" when calling a method inside
>>>> info
>>>> entity, e.g. setFields() ?
>>>>
>>>
>>> No, when $order->getInfo was called, probably only a proxy was loaded.
>>> When executing setFields() the actual entity was loaded and that failed.
>>> Maybe you are trying to set the ID of that entity with setFields()? Just
>>> guessing.
>>>
>>> --
>>> 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] <javascript:>.
>>> To post to this group, send email to [email protected]<javascript:>
>>> .
>>> Visit this group at http://groups.google.com/group/doctrine-user.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>
--
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/d/optout.