File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
test_app/TestApp/Model/Table Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -1770,6 +1770,25 @@ public function testFormatDeepDistantAssociationRecords() {
1770
1770
$ this ->assertEquals ($ expected , $ query ->toArray ());
1771
1771
}
1772
1772
1773
+ /**
1774
+ * Tests that custom finders are applied to associations when using the proxies
1775
+ *
1776
+ * @return void
1777
+ */
1778
+ public function testCustomFinderInBelongsTo () {
1779
+ $ table = TableRegistry::get ('ArticlesTags ' );
1780
+ $ table ->belongsTo ('Articles ' , [
1781
+ 'className ' => 'TestApp\Model\Table\ArticlesTable ' ,
1782
+ 'finder ' => 'published '
1783
+ ]);
1784
+ $ result = $ table ->find ()->contain ('Articles ' );
1785
+ $ this ->assertCount (4 , $ result ->extract ('article ' )->filter ()->toArray ());
1786
+ $ table ->Articles ->updateAll (['published ' => 'N ' ], ['1 = 1 ' ]);
1787
+
1788
+ $ result = $ table ->find ()->contain ('Articles ' );
1789
+ $ this ->assertCount (0 , $ result ->extract ('article ' )->filter ()->toArray ());
1790
+ }
1791
+
1773
1792
/**
1774
1793
* Tests that it is possible to attach more association when using a query
1775
1794
* builder for other associations
Original file line number Diff line number Diff line change @@ -25,6 +25,16 @@ public function initialize(array $config) {
25
25
$ this ->hasMany ('ArticlesTags ' );
26
26
}
27
27
28
+ /**
29
+ * Find published
30
+ *
31
+ * @param Cake\ORM\Query $query The query
32
+ * @return Cake\ORM\Query
33
+ */
34
+ public function findPublished ($ query ) {
35
+ return $ query ->where (['published ' => 'Y ' ]);
36
+ }
37
+
28
38
/**
29
39
* Example public method
30
40
*
You can’t perform that action at this time.
0 commit comments