Multiple Joins to the same Table

Multiple Joins to the same Table

benstebenste Posts: 3Questions: 2Answers: 0
edited August 2018 in Free community support

Hi,

I just started using DataTables and I ran into one problem.

I have a crew user table and a user table, the crew user table has a unique ID, a name and 3 fields with a user_id.
There was no problem of getting the first user ID to a name with the id as value and also get a list of users for the editor select function.

But what can I do to get the same thing done for remaining two user_id fields?

I tried something like this, but there is no relation defined for the second field and if I create a second left join I run into an error as well.

Field::inst( 'Crew.user_id_crewboss' )
->options( Options::inst()
->table( 'Users' )
->value( 'user_id' )
->label( 'user_lastname' )
)
->validator( Validate::dbValues() ),
Field::inst( 'Crew.user_id_crewcook' )
->options( Options::inst()
->table( 'Users' )
->value( 'user_id' )
->label( 'user_lastname' )
)
->validator( Validate::dbValues() )
)
->leftJoin( 'Users', 'Crew.user_id_crewboss', '=', 'Users.user_id' )
->process( $_POST )
->json();

Thanks for your help.

Ben

Answers

  • benstebenste Posts: 3Questions: 2Answers: 0

    Found a solution.

    ->leftJoin( 'Users', 'Crew.user_id_crewboss', '=', 'Users.user_id', 'Users', 'Crew.user_id_cook', '=', 'Users.user_id' )

    Can be closed.

This discussion has been closed.