Get value from one to many join on server side with postCreate

Get value from one to many join on server side with postCreate

lincolncbennettlincolncbennett Posts: 23Questions: 10Answers: 1

Hi,

I'm using datatables to send invoices to clients. I use 2 datatables (invsent and payees). I am using a one to many join to select a payee to send the invoice on the server side script for invsent editor.

Field::inst( 'invsent.sent_inv' )
             ->options( Options::inst()
                ->table( 'payees' )
                ->value( 'id' )
                ->label ( array( 'payee_name', 'payee_email' ))
                ->render( function ( $row ) {
              return $row['payee_name'].' ('.$row['payee_email'].')';})
                ->where( function ($q) {
                  $q->where( 'client_id', $_GET['GalleryID'] , '=' );
                })
              )      
            ->validator( Validate::dbValues()),

I then use a postCreate function and PHP mailer on the same script to send the invoice to the payee

 $mail->addAddress($values['payees']['payee_email'], '');     // Add a recipient

this is throwing the error: Undefined index: payees which I understand as it is not sent by editor on create.
As you can see I am trying to get the value of the payee_email to use as the address to send the invoice but I am not sure how to get this on create. If I set ->value( 'id' ) to ->value( 'email' ), I can get the email in the invsent table and use

 $mail->addAddress($values['invsent']['sent_inv'], '');     // Add a recipient

but then I would be joining the tables using the email address rather than the id which would be bad if the payees email address had to be changed.

any help would be greatly appreciated.

Answers

  • lincolncbennettlincolncbennett Posts: 23Questions: 10Answers: 1

    So basically my question is how do use the value from a joined table in a postCreate function on the server side. :)

  • lincolncbennettlincolncbennett Posts: 23Questions: 10Answers: 1

    Okay, silly me.
    the correct way is

    $mail->addAddress($row['payees']['payee_email'], ''); 
    
  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    That's it - thanks for reporting back,

    Colin

This discussion has been closed.