Laravel Model with Two Primary Keys update [duplicate]

I’ve run into this problem a couple of times. You need to override some properties: protected $primaryKey = [‘user_id’, ‘stock_id’]; public $incrementing = false; and methods (credit): /** * Set the keys for a save update query. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ protected function setKeysForSaveQuery(Builder $query) { $keys = $this->getKeyName(); if(!is_array($keys)){ … Read more

Foreign key relationship with composite primary keys in SQL Server 2005

Since Table2 has a composite primary key (FileID, FileType), then any reference to it must also include both columns. ALTER TABLE dbo.Table1 ADD CONSTRAINT FK_Table1_Table2 FOREIGN KEY(FileID, FileType) REFERENCES Table2(FileID, FileType) Unless you have a unique constraint/index on the Table2.FileID field (but if so: why isn’t this the PK??), you cannot create a FK relationship … Read more

How I can put composite keys in models in Laravel 5?

I wrote this simple PHP trait to adapt Eloquent to handle composite keys: <?php namespace App\Model\Traits; // *** Adjust this to match your model namespace! *** use Illuminate\Database\Eloquent\Builder; trait HasCompositePrimaryKey { /** * Get the value indicating whether the IDs are incrementing. * * @return bool */ public function getIncrementing() { return false; } /** … Read more

How to create and handle composite primary key in JPA

You can make an Embedded class, which contains your two keys, and then have a reference to that class as EmbeddedId in your Entity. You would need the @EmbeddedId and @Embeddable annotations. @Entity public class YourEntity { @EmbeddedId private MyKey myKey; @Column(name = “ColumnA”) private String columnA; /** Your getters and setters **/ } @Embeddable … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)