yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

Compound Primary Key #132

Open NBA707 opened 11 months ago

NBA707 commented 11 months ago

Summary of problem or feature request

I have a table that has 2 fields which are primary keys from different tables. It's primary key is unique compound partent tables fields. PK_TABLE3 - UNIQUE - COLUMNS: TABLE1_ID, TABLE2_ID When I do the ->save() it comes back with an error: Error Code : 904 Error Message : ORA-00904: "ID": invalid identifier Position : 91 Statemen

Code snippet of problem

$table3 = new Table3();
$table3->table1_id = $table1->id;
$table3->table2_id = $table2->id;
$table3->save();

System details

NBA707 commented 11 months ago

Should I just do raw sql, or is there a way to set the primary key to be two fields in the model via public $primaryKey =

yajra commented 11 months ago

Laravel does support composite primary key afaik so you have to do saving manually like on your example. I think there are packages created for this purpose.

A quick search yields to https://github.com/thiagoprz/eloquent-composite-key. Maybe give it a try?