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,studensteachers and teachers,like robot,robotparts,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=getStudentsteacher(array('studentsid'=>array(1,2,3)));

if not,how ?



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

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

http://docs.phalconphp.com/en/latest/reference/models.html#bidirectional-relations



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