How to reference Composite Key in Models?

Posted 4 years ago by mikebronner

OK, so I set up my table using schema builder with a composite primary key using the following hypothetical:

            $table->integer('age')->unsigned();
            $table->integer('height')->unsigned();
            $table->integer('weight')->unsigned();
            $table->integer('shoeSize')->unsigned();
            $table->primary(['age', 'height', 'weight', 'shoeSize']);

Now, since 'id' field does not exist, I need to tell my model what to use as a primary key?

class Individual extends \Eloquent
{
    protected $primaryKey = ????;
    [...]
}

Do I tell it to use an array, like $primaryKey = ['age', 'height', 'weight', 'shoeSize'];?

Please sign in or create an account to participate in this conversation.