Permalink
Browse files

Adding test to show exception is thrown when not enough froeignKeys are

provided
  • Loading branch information...
1 parent 5cde159 commit 9e1d36985149d7d9a3d5b07f649cb027a0fa8f82 @lorenzo lorenzo committed Jan 8, 2014
Showing with 21 additions and 0 deletions.
  1. +21 −0 Test/TestCase/ORM/Association/BelongsToTest.php
@@ -291,4 +291,25 @@ public function testAttachToMultiPrimaryKey() {
]);
$association->attachTo($query);
}
+
+/**
+ * Tests that using belongs to with a table having a multi column primary
+ * key will work if the foreign key is passed
+ *
+ * @expectedException \RuntimeException
+ * @expectedExceptionMessage Cannot match provided foreignKey, got 1 columns expected 2
+ * @return void
+ */
+ public function testAttachToMultiPrimaryKeyMistmatch() {
+ $this->company->primaryKey(['id', 'tenant_id']);
+ $query = $this->getMock('\Cake\ORM\Query', ['join', 'select'], [null, null]);
+ $config = [
+ 'foreignKey' => 'company_id',
+ 'sourceTable' => $this->client,
+ 'targetTable' => $this->company,
+ 'conditions' => ['Companies.is_active' => true]
+ ];
+ $association = new BelongsTo('Companies', $config);
+ $association->attachTo($query);
+ }
}

0 comments on commit 9e1d369

Please sign in to comment.