Thanks a lot Herman, I did this:

foreach ($orders as $order) {
              $info = $order->getInfo();
              $info->setFields($_POST, array(.....));
}
Now I get entity was not found for setField(), now getInfo() does not give
error like before. How can I load $info as entity to update some properties?






On Sun, Apr 20, 2014 at 6:34 PM, Herman Peeren <[email protected]>wrote:

> $em->find('Entities\Product', $_POST['productId'])->getOrders() gives back
> a collection (of orders).
> You now try to do getInfo() on that collection, but Doctrine's collection
> class doen't have a getInfo() method.
>
> If you want to do a getInfo() on each individual order, so you'll have to
> loop through the collection:
>
> foreach ($orders as $order) {
>     $productInfo = $order->getInfo(); // and do something with that
> $productInfo.
>
> }
>
>
>
> On Sunday, 20 April 2014 14:21:18 UTC+2, Parsifal wrote:
>
>> Thanks herman for helping me how to use getProduct method rather than dql.
>> Just a question:
>>
>> relation from Product to Order:
>> $metadata->mapOneToMany(array( 'fieldName' => 'orders',
>>                                'targetEntity' => 'Entities\\Order',
>>                                'mappedBy' => 'product',
>>                                'joinColumns' => array( 0 => array( 'name'
>> => 'product_id',
>>
>> 'referencedColumnName' => 'product_id',
>>
>> 'nullable' => true,
>>
>> 'columnDefinition' => NULL,
>>                                                       ), )
>> ));
>>
>> In product entity I defined:
>>     public function getOrders()
>>     {
>>          return $this->orders;
>>     }
>>
>> ======
>> relation from Order to Info:
>> $metadata->mapOneToOne(array( 'fieldName' => 'info',
>>                                'targetEntity' => 'Entities\\Info',
>>                                'inversedBy' => 'order',
>>                                'mappedBy' => 'order',
>>                                'joinColumns' => array( 0 => array( 'name'
>> => 'id',
>>
>> 'referencedColumnName' => 'order_id',
>>
>> 'nullable' => true,
>>
>> 'columnDefinition' => NULL,
>>                                                       ), )
>> ));
>>
>> In order entiry I defined:
>>     public function getInfo()
>>     {
>>          return $this->info;
>>     }
>>
>> Now I need to have:
>> $products = $em->find('Entities\Product', $_POST['productId'])->
>> getOrders()->getInfo();
>>
>> But I get:
>> Call to undefined method Doctrine\ORM\PersistentCollection::getInfo()
>> but I have getInfo() method in Order entity, what wrong I did?
>>
>>
>>
>>
>>
>> On Fri, Apr 4, 2014 at 1:38 PM, Herman Peeren <[email protected]>wrote:
>>
>>> All I was saying there is that your:
>>>
>>>
>>>     public function getProduct() {
>>>        return $this->ProductId;
>>>      }
>>>
>>> Sould be something like:
>>>
>>>     public function getProduct() {
>>>        return $this->*product*; // Return a Product, not an id of a
>>> Product.
>>>      }
>>>
>>>
>>> On Friday, 4 April 2014 10:29:32 UTC+2, Parsifal wrote:
>>>
>>>> Thanks Herman,
>>>> A bit confusion in your last email to me as below. If I understood
>>>> correctly in getProduct function it should be something like:
>>>> fuction getProduct($id) {
>>>>    return $em->find('Product', $id);
>>>> }
>>>> Right? And this function should be in Product entity class file itself?
>>>> Please clarify if I understood you correctly.
>>>> در 2014 3 20 22:45، "Herman Peeren" <[email protected]> نوشت:
>>>>
>>>>>  Hmmm was about to finally shut down my computer and saw your last
>>>>> message.* NO!!!* *getProduct() doen't return a ProductId but a
>>>>> Product!!!* That is the essence of why we do this all! In
>>>>> getProduct() you have nothing to do with an id. It's just what the name
>>>>> sais: getProduct() gets a Product, can't be simpler. Idem with getInfo().
>>>>> The id is only necessary for the mapping. And maybe if you want to find a
>>>>> specific Product outside of this model.
>>>>>
>>>>>
>>>>> On Thursday, 20 March 2014 22:24:51 UTC+1, Parsifal wrote:
>>>>>>
>>>>>> Thanks a lot. Just a quick check with you for sure:
>>>>>> In "X" entity I add this:
>>>>>>
>>>>>> public function getProduct() {
>>>>>>    return $this->ProductId;
>>>>>> }
>>>>>>
>>>>>> Then in "Info" entity I have this:
>>>>>>
>>>>>> public function getInfo() {
>>>>>>    return $this->ProductId;
>>>>>> }
>>>>>>
>>>>>> Then use with:
>>>>>> $specificX->getProduct()-getInfo();
>>>>>>
>>>>>> Right? Or what these functions should be? I guess getInfo() should be
>>>>>> in Product entity instead of Info entity? If yes, what should be inside 
>>>>>> the
>>>>>> function that it loads Info entity?
>>>>>>
>>>>>  --
>>>>> 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.
>>>>>
>>>>  --
>>> 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.
>>>
>>
>>  --
> 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.
>

-- 
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.

Reply via email to