Repository->findBy( ) gives back a *collection *of entities. So you'll have 
to loop over them to set their fields. If you are shure you'll only 
get/want at most 1 entity back you can use Repository->findOneBy( ). 
Repository->find( ) searches in a primary key, so it can only get at most 1 
entity back. EntityManager->find ( ) is just a shortcut for 
Repository->find( ).

You are still mainly thinking in tables and records. Why are you using an 
ORM? For if you want to update tables and records, it would probably be 
easier to just write SQL directly, without Doctrine. No critic, just 
wondering. 


On Sunday, 9 March 2014 17:08:28 UTC+1, Parsifal wrote:
>
> Thanks for trying to help. Actually I have a form and when submitting I 
> want to update the related record in db using persist/flush. How doctrine 
> will know which row should be updated? using this:
> $something = $em->find('Entities\Something', $_POST['id']);
> $something->setFields($_POST, array('blah'));
> $something->persist($something);
> $something->flush();
>
> with first line, it gets the row that should be updated, with second line 
> it sets the updated value posted by form, then persist/flush.
> but ->find will fetch the row by identifier, I have another coloumn that 
> is not an incremented id (identifier) coloumn like example above but that 
> is a coloumn to be used to join to another table, I want to find the record 
> by that coloumn rather than identifier to update it. How possible? findBy() 
> is valid only for repository not for EntityManager. so what should I do? 
> something like below obviously will not work:
>  
> $something = $em->find*By*('Entities\Something', array('age' = > 
> $_POST['age']));
> $something->setFields($_POST, array('blah'));
> $something->persist($something);
> $something->flush();
>  
> So what can I do? Please advice.
>  
>  
>

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