Field options from left joined table

Field options from left joined table

edanyildizedanyildiz Posts: 43Questions: 13Answers: 4

Dear Allan,

I have multiple tables,
1) Customers
2) Companies

When i am adding a select field, is it possible to add other joined tables data?

Field::inst( 'offers.customer' )
        ->options( 'customers', 'id', array('firstname', 'lastname'), null, function ( $row ) {
        return $row['firstname'].' '.$row['lastname'];} )   
        ->validator( 'Validate::dbValues' ) ,

In above example, is it possible to return firstname + lastname + company (from other left joined table) ?

the join structure is like below;

$editor->leftJoin( 'customers', 'customers.id', '=', 'offers.customer' );
$editor->leftJoin( 'companies', 'companies.id', '=', 'customers.company' )

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,873Questions: 1Answers: 10,528 Site admin

    As in you want to show left joined information in the labels of the options?

    That's not something that is currently possible wit the Options class in the PHP and .NET libraries I'm afraid. Having said that, it probably wouldn't be too difficult to add.

    ALlan

  • edanyildizedanyildiz Posts: 43Questions: 13Answers: 4

    Yes, i like to show name+surname+ company name in options.
    So, there is nothing to do for now.
    thanky you.

  • allanallan Posts: 63,873Questions: 1Answers: 10,528 Site admin
    Answer ✓

    I'm sorry to say not with the provided PHP and .NET libraries. They do provide the ability to get the data from the database yourself though. That would be the best way of doing this I think - have your own join based query to get the options.

    Allan

This discussion has been closed.