We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

help~input some student and output 1 teacher,how to do it?(input some id ,output 1 id)

it is about manyToMany.

some students have one teacher, some teachers have one student.

I have 3 forms:studens,studens_teachers and teachers,like robot,robot_parts,parts. If i want find the only one teacher of 3 students called jack,bob,and michael ,and their ID in studens_teachers are 1,2 and 3.Can i do this? :

$theOnlyOneTeacherID=getStudents_teacher(array('students_id'=>array(1,2,3)));

if not,how ?



623
edited Mar '15

thank you,but the two links doesn't had any answer for itself or my question...

Here are a couple of links which might help you:

https://www.calinrada.com/many-to-many-relationships-phalcon/

https://docs.phalcon.io/en/latest/reference/models.html#bidirectional-relations



43.9k
edited Mar '15

Hi,

you may use query bulder:


$teachers = $this->modelsManager->createBuilder()
    ->from('StudendsTeachers')
     ->where('student_id = 1')
     ->andWhere('student_id = 2');
    ->getQuery()
    ->execute();

btw, I'm not sure that you will get an unique record with the kind of relations you are using ...