From dc6181f8135c67747ceb97a16870c0706f4082bb Mon Sep 17 00:00:00 2001 From: David Yell Date: Thu, 13 Jun 2013 11:20:33 +0100 Subject: [PATCH 1/2] Fixed the example in the readme for filtering by related model data --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c0f9b1a..6d9d7d9 100644 --- a/README.md +++ b/README.md @@ -96,11 +96,20 @@ If you were to try this example with containable, you would find that it generat ### Filtering a parent model by records in a child model: - - $this->Article->find('all', array( - 'contain' => array('Author'), - 'link' => array('Comment' => array('conditions' => array('Comment.user_id' => 1))) - )); +```php +Article->find('all', array( + 'contain' => array( + 'Author' + ), + 'link' => array( + 'Comment' + ), + 'conditions' => array( + 'Comment.user_id' => 1 + ) +)); +``` Previous example will bring all articles having a comment done by user 1. Please notice that if there is more than one comment per article done by such user, this query will actually return an Article record per each comment made. This is because Linkable From 21d6c4079b909aeb7879dabf163f4e5d2aa9b981 Mon Sep 17 00:00:00 2001 From: David Yell Date: Thu, 13 Jun 2013 11:25:38 +0100 Subject: [PATCH 2/2] Updated readme to use syntax highlighting --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6d9d7d9..e435849 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Redistributions of files must retain the above copyright notice. ## Installation ## If you are using composer, add this to your composer.json file: - +```json { "extra": { "installer-paths": { @@ -30,6 +30,7 @@ If you are using composer, add this to your composer.json file: "lorenzo/linkable": "master" } } +``` Otherwise just clone this repository inside your app/Plugin folder: @@ -44,18 +45,19 @@ CakePlugin::load('Linkable'); ### Configuration To use this behavior, add it to your AppModel: - +```php TestRun->CasesRun->find('all', array( 'link' => array( @@ -74,7 +76,7 @@ Here's an example using both linkable 'CasesRun.id', 'CasesRun.state', 'CasesRun.modified', 'CasesRun.comments' ) )); - +``` Relatioships: * CasesRun is the HABTM table of TestRun <-> TestCases @@ -87,11 +89,11 @@ Relatioships: Output SQL: - +```sql SELECT `CasesRun`.`id`, `CasesRun`.`state`, `CasesRun`.`modified`, `CasesRun`.`comments`, `User`.`username`, `TestCase`.`automated`, `TestCase`.`name`, `TestSuite`.`name`, `TestHarness`.`name` FROM `cases_runs` AS `CasesRun` LEFT JOIN `users` AS `User` ON (`User`.`id` = `CasesRun`.`user_id`) LEFT JOIN `test_cases` AS `TestCase` ON (`TestCase`.`id` = `CasesRun`.`test_case_id`) LEFT JOIN `test_suites` AS `TestSuite` ON (`TestSuite`.`id` = `TestCase`.`test_suite_id`) LEFT JOIN `test_harnesses` AS `TestHarness` ON (`TestHarness`.`id` = `TestSuite`.`test_harness_id`) WHERE `test_run_id` = 32 SELECT `Tag`.`id`, `Tag`.`name`, `CasesRunsTag`.`id`, `CasesRunsTag`.`cases_run_id`, `CasesRunsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `cases_runs_tags` AS `CasesRunsTag` ON (`CasesRunsTag`.`cases_run_id` IN (345325, 345326, 345327, 345328) AND `CasesRunsTag`.`tag_id` = `Tag`.`id`) WHERE 1 = 1 - +``` If you were to try this example with containable, you would find that it generates a lot of queries to fetch all of the data records. Linkable produces a single query with joins instead.