|
|
@@ -434,4 +434,26 @@ class BelongsToTest extends TestCase
|
|
|
return $q->applyOptions(['something' => 'more']);
|
|
|
}]);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test that failing to add the foreignKey to the list of fields will throw an
|
|
|
+ * exception
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testAttachToNoFieldsSelected()
|
|
|
+ {
|
|
|
+ $articles = $this->getTableLocator()->get('Articles');
|
|
|
+ $association = $articles->belongsTo('Authors');
|
|
|
+
|
|
|
+ $query = $articles->find()
|
|
|
+ ->select(['Authors.name'])
|
|
|
+ ->where(['Articles.id' => 1])
|
|
|
+ ->contain('Authors');
|
|
|
+ $result = $query->firstOrFail();
|
|
|
+
|
|
|
+ $this->assertNotEmpty($result->author);
|
|
|
+ $this->assertSame('mariano', $result->author->name);
|
|
|
+ $this->assertSame(['author'], array_keys($result->toArray()), 'No other properties included.');
|
|
|
+ }
|
|
|
}
|