Skip to content

ionas/linkable

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Linkable Plugin
CakePHP Plugin - PHP 5 only

LinkableBehavior. Taking it easy in your DB.

This is a fork by GiulianoB (on github)
It provides the following new features:
-Plays nice with Containable which means that you can force INNER JOINS for hasOne/belongsTo and at the same time do a query on a hasMany/HABTM relationship.
 
-The original code required the relationship to be established from the target to the source. 
(e.g. if you are linking Post => User then User would have to define a hasOne Post relationship. 
However, this proves problematic when doing on-the-fly binds as you would have to bind on more than just the model you are querying from)
 
This hasn't gotten much testing but here is an example of how it can be used.

Relationships involved:
CasesRun is the HABTM table of TestRun <-> TestCases
CasesRun belongsTo TestRun
CasesRun belongsTo User
CasesRun belongsTo TestCase
TestCase belongsTo TestSuite
TestSuite belongsTo TestHarness
CasesRun HABTM Tags

$this->TestRun->CasesRun->find('all', array(	
	'link' => array(
		'User' => array('fields' => 'username'), 
		'TestCase' => array('fields' => array('TestCase.automated', 'TestCase.name'),
			'TestSuite' => array('fields' => array('TestSuite.name'), 
				'TestHarness' => array('fields' => array('TestHarness.name'))
			)
		)
	),
	'conditions' => array('test_run_id' => $id),
	'contain' => array(
		'Tag'					
	),
	'fields' => array(
		'CasesRun.id', 'CasesRun.state', 'CasesRun.modified', 'CasesRun.comments'
	)
))

Example output 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 

About

Linkable plugin for CakePHP, with LinkableBehavior the ContainableBehavior's ass kicker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published