0
votes

I'm having a problem saving the data to the database. I can't seem to figure how one-to-many works. So heres the scenario: One journal voucher has many entries in it (debits and credits).

Vouchers Table

| voucher_id(pk) | voucherNo | notes | amount | date |

Entries Table

| entry_id(pk) | voucher_id(fk) accountname | description | debit | credit |

EntriesTable $this->belongsTo('Vouchers', [ 'foreignKey' => 'voucher_id', 'joinType' => 'INNER' ]);

1

1 Answers

0
votes

From the vouchers's side you should be fine as described in the cookbook: https://book.cakephp.org/3.0/en/orm/saving-data.html#saving-hasmany-associations

From the entries side is not the normal way, but you can do it also: https://book.cakephp.org/3.0/en/orm/saving-data.html#saving-belongsto-associations