php - How to create a join table record -


so i'm trying add record join table, doesn't seem work, no errors given either.

so here's data array (which saves correctly without problem)

array(3) {     ["id"]=>     string(2) "32"     ["title"]=>     string(5) "hello"     ["participant"]=>     array(1) {     [0]=>         array(1) {           ["id"]=>           int(1)         }       } } 

my belongs many:

$this->belongstomany('participants', [         'foreignkey' => 'item_id',         'targetforeignkey' => 'participant_id',         'classname' => 'users',         'jointable' => 'participants_items'     ]); 

belongs many in users:

$this->belongstomany('myitems', [         'foreignkey' => 'participant_id',         'targetforeignkey' => 'item_id',         'classname' => 'items',         'jointable' => 'participants_items'     ]); 

the following methods i've tried apply join table record:

$data['participants'] = [ //also tried participant, participants, participant     ['id' => 1] ]; 

and also:

$data['participants'] = [     '_ids' => [1, 2] ]; 

what doing wrong? no errors & no entries

i've found mistake in newentity() part!

before(broken): $newentity = $this->newentity($inputdata]);

after(fixed): $newentity = $this->newentity($inputdata, ['associated' => ['participants']])

and before executing newentity add id's data list following:

$inputdata['participants'] = [     '_ids' => [10, 12] ]; 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -