Creating one record in each table with the Editor
Creating one record in each table with the Editor
Hello,
i'm struggling with one issue...
I want to create something very simple:
A user can add a new song + artist with a Datatable Editor which looks like that:
Title_ID | Artist | Title | BPM | Capo | some more columns.. |
My MySQL database looks like that:
Title_Table
Title_ID; Title_Artist_ID; Title; BPM; Capo; some more columns..
Artist Table
Artist_ID; Artistname
Now i want to enter the Artist Name, Title, BPM etc... if the artist does not exist a new record is added to the Artist Table and its ID is added to the Title Table. Example:
Artist Table:
0 Johnny Cash
Title Table:
0; 0; Hurt; 80; 3; some more info...
The Editor will now show:
Titel ID | Artist | Title | BPM | Capo | .....
0 | Johnny Cash | Hurt | 80 | 3 | .......
The issue now, i don't get it to work... why does he not add the artist to the artist Table?
My php looks like that:
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Event,
DataTables\Editor\Validate;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'TITEL', 'titel_id' )
->fields(
Field::inst( 'TITEL.titel_id' ),
Field::inst( 'ARTIST.artist' ),
Field::inst( 'TITEL.titel_bezeichnung' ),
Field::inst( 'TITEL.link' ),
Field::inst( 'TITEL.bpm' ),
Field::inst( 'TITEL.capo' ),
Field::inst( 'TITEL.original_key' ),
Field::inst( 'TITEL.played_key' )
)
->LeftJoin( 'ARTIST', 'artist_id', '=', 'titel_artist_id' )
->process( $_POST )
->json();