Is it possible to create composite Primary Keys in Records?
It would appear not unfortunately.

Craft's BaseRecord (which a Record should inherit from) tries to uses the primaryKey() method call to help create the table, but assumes a single column name is returned, not an Array and so falls over on the isset call.

$pk = $this-&gt;primaryKey();

if (isset($columns[$pk]))
{
  $columns[$pk]['primaryKey'] = true;
  $addIdColumn = false;
}
else
{
  $addIdColumn = true;
}


I'm guessing it should work because the CActiveRecord (which the BaseRecord inherits from) states in it's comments for PrimaryKey:

@return mixed the primary key of the associated database table.

If the key is a composite one consisting of several columns, it should
return the array of the key column names.


EDIT: In the end I added the following to my Plugin file, and that seemed to do the trick:

public function onAfterInstall()
{
  craft()-&gt;db-&gt;createCommand()-&gt;dropColumn('myplugin_merchant_order', 'id');
  craft()-&gt;db-&gt;createCommand()-&gt;addPrimaryKey('myplugin_merchant_order', ['merchant_id', 'order_id']);
}


I also had to add this to my Record, to stop the validation failing because I'd removed the id column in the above step:

public function primaryKey()
{
    return null;
}