Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compound Primary Key #132

Open
NBA707 opened this issue Oct 27, 2023 · 2 comments
Open

Compound Primary Key #132

NBA707 opened this issue Oct 27, 2023 · 2 comments

Comments

@NBA707
Copy link

NBA707 commented Oct 27, 2023

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

  • Ubuntu 20.04
  • PHP 8.2.11
  • PDO-VIA-OCI8 Version 9.5.1
@NBA707
Copy link
Author

NBA707 commented Oct 27, 2023

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
Copy link
Owner

yajra commented Nov 3, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants