BoomyJee
BoomyJee

Reputation: 61

findBy relation field

class Profile {
    /** @OneToMany(targetEntity="Link", mappedBy="owner") */
    private $links;  
}

class Link {
    /**
    * @ManyToOne(targetEntity="Profile", inversedBy="links")
    * @JoinColumn(name="owner_id", referencedColumnName="id")
    */    
    public $owner;
    /**
     * @ManyToOne(targetEntity="Profile")
     * @JoinColumn(name="subject_id", referencedColumnName="id")
     */    
    public $subject;    
}

$em->findBy(array("owner"=>$owner,"subject"=>$subject)); 

gives Unrecognized field: owner

there is a workaround of course, but it looks ugly

$em
->createQuery('SELECT l FROM \Dating\Models\Link l WHERE l.owner = ?1 AND l.subject = ?2')
->setParameter(1,$owner)
->setParameter(2,$subject)
->getResult();

is there any chance using findBy without writing my own method?

Upvotes: 1

Views: 2704

Answers (2)

meze
meze

Reputation: 15087

All is correct in your code. Doctrine2 is currently in BETA and it was a bug in beta4. Try to download the latest version from GIT and it should work!

Upvotes: 1

Maerlyn
Maerlyn

Reputation: 34107

owner is not a field, owner_id is. Try using that.

Upvotes: 0

Related Questions