assuming my setup is
Teachers (id, name)
Students (id, name, teacher [FK]);
how do i select in DQL teachers that have students? i guess it will be something like
select t FROM Entities\Teachers t WHERE count(t.students) > 0
but i know count(t.students) > 0
is wrong ... what do i use then?
UPDATE
now what abt a many to many self referencing relationship? where a User can be a Teacher or Student or both ... code below ... whats the DQL for getting users that have students?
/** @Entity @Table(name="users")) */
class User {
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(type="string", length="30")
*/
private $name;
/**
* @ManyToMany(targetEntity="User", inversedBy="teachers")
* @JoinTable(name="Teachers_Students",
* joinColumns={@JoinColumn(name="teacher", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="student", referencedColumnName="id")}
* )
*/
private $students;
/**
* @ManyToMany(targetEntity="User", mappedBy="students")
*/
private $teachers;