How to submit primary key

How to submit primary key

dataman123dataman123 Posts: 4Questions: 1Answers: 0

Hello, looks like I'm missing something!
If this is my editor instance:

require 'editor.php';

use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Options,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST

$editorInstance = Editor::inst( $db, 'overall_budgets' )
->fields(
    Field::inst( 'overall_budgets.id' ),
    Field::inst( 'overall_budgets.consumer_name' )
    ->options( Options::inst()
            ->table( 'consumers' )
            ->value( 'lower(concat(consumers.lname, consumers.fname))' )
            ->label( 'concat(consumers.lname, ", ", consumers.fname)' )
        ),
    Field::inst( 'consumers.id')
)
->leftJoin( 'consumers',   'lower(concat(consumers.lname, consumers.fname))',   '=', 'overall_budgets.consumer_name' )
->process( $_POST )
->debug(true)
->json();

What do I need to include to be able to edit entries in the left-joined table?

I tried putting this after my editor:

editor.add( {
    type:    "hidden",
    name:    "consumer_name"
} );

but that didn't seem to do anything at all.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 51,923Questions: 1Answers: 7,873 Site admin

    What field(s) do you want to edit on the customers table? You'd need to include the following in the JS fields:

    editor.add( {
        type:    "hidden",
        name:    "consumers.id"
    } );
    

    But from what is shown there, I don't see any thing in the customers table that should actually be edited - just the two fields in the overall_budgets table.

    Allan

  • dataman123dataman123 Posts: 4Questions: 1Answers: 0

    You're right - I left out a lot of the code. I'm trying to edit the DDRO for the consumer, like this:

    $editorInstance = Editor::inst( $db, 'overall_budgets' )
    ->fields(
        Field::inst( 'overall_budgets.id' ),
        Field::inst( 'overall_budgets.consumer_name' )
        ->options( Options::inst()
                ->table( 'consumers' )
                ->value( 'lower(concat(consumers.lname, consumers.fname))' )
                ->label( 'concat(consumers.lname, ", ", consumers.fname)' )
            ),
        Field::inst( 'consumers.id'),
        Field::inst('consumers.ddro')
    )
    ->leftJoin( 'consumers',   'lower(concat(consumers.lname, consumers.fname))',   '=', 'overall_budgets.consumer_name' )
    ->process( $_POST )
    ->debug(true)
    ->json();
    

    I tried adding the hidden field to the js fields like in your answer.
    I tried adding
    ->pkey('id')
    to the $editorInstance.
    I tried anything I could think of :) .
    But the DDRO field still does not update in the consumers table - it just stays the same.

    I see that it's being submitted properly - the headers tab in the Network pane shows
    data[row_5][consumers][ddro]: Bernard Fineson (The right info),
    but the response JSON has ddro:null

    In the meantime I'm using a workaround where a new consumers editor is triggered by the regular editor. But it's clunky - not the best answer.

  • allanallan Posts: 51,923Questions: 1Answers: 7,873 Site admin

    Can you show me the full set of parameters being submitted to the server please? Does it include consumers.id as well?

    Allan

  • dataman123dataman123 Posts: 4Questions: 1Answers: 0

    Nope - here's the whole set of form data submitted:
    data[0][overall_budgets][consumer_fname]: Keilu
    data[0][overall_budgets][consumer_lname]: Customer
    data[0][overall_budgets][dpp_number]: 12345678
    data[0][overall_budgets][request_startup_broker]: 0
    data[0][overall_budgets][ddp_adaptive]: 10
    data[0][overall_budgets][ddp_health]: 10
    data[0][overall_budgets][ddp_behavior]: 10
    data[0][overall_budgets][template_funding_approved]: 0
    data[0][overall_budgets][template_funding_type]: Specialized
    data[0][overall_budgets][pra_residential]: 12
    data[0][overall_budgets][pra_otr]: 12
    data[0][overall_budgets][pra_both]: 12
    data[0][overall_budgets][budget_type]: blabla
    data[0][overall_budgets][requested_services]: {requested:yes}
    data[0][consumers][broker_cert_number]: 123456
    data[0][consumers][fname]: fake
    data[0][consumers][lname]: dummy
    data[0][consumers][ddro]: Bernard Fineson
    data[0][consumers][regional_office]: New York
    data[0][consumers][ddro_contact]: Yisi
    data[0][consumers][ddro_phone]: 7183272500
    data[0][consumers][ddro_email]: fakeaddress@gmail.com
    data[0][consumers][fiscal_int_agency]: mdcsbsrespite
    data[0][consumers][fiscal_int_contact]: none
    data[0][consumers][fiscal_int_address1]: 533 Oak Lane
    data[0][consumers][fiscal_int_address2]: Los Angeles, CA 12345
    data[0][consumers][fiscal_int_email]: rochelfried9@gmail.com
    data[0][consumers][fiscal_int_phone]: 71848499039
    data[0][consumers][fiscal_int_corp_id]: 191919
    data[0][consumers][broker_name]: Jela Tean
    data[0][consumers][broker_address1]: Harabi 7
    data[0][consumers][broker_address2]: Anytown, PA
    data[0][consumers][broker_email]: fakeaddress@gmail.com
    data[0][consumers][broker_phone]: 7183276666
    data[0][consumers][broker_agency]: hestuck
    data[0][consumers][care_manager]: carry manager
    data[0][consumers][care_manager_address1]: 123 Sesame Street
    data[0][consumers][care_manager_address2]: sesame, 12345
    data[0][consumers][care_manager_email]: bugle@gmail.com
    data[0][consumers][care_manager_phone]: 918499039
    data[0][consumers][care_manager_agency]: qsac
    data[0][consumers][css_partic_10_14]:
    data[0][consumers][id]:
    action: create

  • dataman123dataman123 Posts: 4Questions: 1Answers: 0

    I've made peace with this workaround and I'm making it work for me :) Thanks!

  • allanallan Posts: 51,923Questions: 1Answers: 7,873 Site admin
    Answer ✓

    Fair enough - we’ll go with that for now then!

    Thanks for the update,
    Allan

Sign In or Register to comment.