Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix #717 joined strategy cleanup. #723

Merged
merged 1 commit into from

2 participants

@jails
Collaborator

Cleanup of #717 have corrupted the joined strategy.

@jails jails referenced this pull request
Closed

Model Relationship #722

@nateabele nateabele referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@nateabele nateabele merged commit c6e4c59 into UnionOfRAD:master
@nateabele
Owner

Hey, I merged this, but had to roll it back right away because I realized it was against master. Also, it seems like Travis never got run on it?

@jails
Collaborator

Yeah sorry, I was getting confused with an extra commit when I PR form master to dev (#699) and finally Instead of doing it from dev to dev, I do it wrong...

@nateabele
Owner

No worries. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 11, 2012
  1. @jails

    Fix strategy cleanup of #717.

    jails authored
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 10 deletions.
  1. +9 −9 data/source/Database.php
  2. +31 −1 tests/cases/data/source/DatabaseTest.php
View
18 data/source/Database.php
@@ -190,9 +190,9 @@ public function __construct(array $config = array()) {
$constraints = array();
$alias = $name;
- if (isset($with[$path])) {
-
- list($unallowed, $allowed) = Set::slice($with[$path], array(
+ $relPath = $path ? $path . '.' . $name : $name;
+ if (isset($with[$relPath])) {
+ list($unallowed, $allowed) = Set::slice($with[$relPath], array(
'alias',
'constraints'
));
@@ -201,16 +201,16 @@ public function __construct(array $config = array()) {
$message .= "`'with'` using the `'joined'` strategy.";
throw new QueryException($message);
}
- extract($with[$path]);
+ extract($with[$relPath]);
}
- $to = $context->alias($alias, $path);
+ $to = $context->alias($alias, $relPath);
if ($needPks) {
$context->fields(array($to => (array) $model::meta('key')));
}
- if ($context->relationships($path) === null) {
- $context->relationships($path, array(
+ if ($context->relationships($relPath) === null) {
+ $context->relationships($relPath, array(
'type' => $rel->type(),
'model' => $rel->to(),
'fieldName' => $rel->fieldName(),
@@ -221,7 +221,7 @@ public function __construct(array $config = array()) {
}
if (!empty($childs)) {
- $me($me, $rel->to(), $childs, "{$path}." . key($childs), $to, $needPks);
+ $me($me, $rel->to(), $childs, $relPath, $to, $needPks);
}
}
};
@@ -233,7 +233,7 @@ public function __construct(array $config = array()) {
$needPks = true;
$context->fields(array($alias => (array) $model::meta('key')));
}
- $strategy($strategy, $model, $tree, key($tree), $context->alias(), $needPks);
+ $strategy($strategy, $model, $tree, '', $context->alias(), $needPks);
},
'nested' => function($self, $model, $context) {
throw new QueryException("This strategy is not yet implemented.");
View
32 tests/cases/data/source/DatabaseTest.php
@@ -24,8 +24,8 @@ class DatabaseTest extends \lithium\test\Unit {
protected $_configs = array();
protected $_model = 'lithium\tests\mocks\data\model\MockDatabasePost';
-
protected $_gallery = 'lithium\tests\mocks\data\model\MockGallery';
+ protected $_imageTag = 'lithium\tests\mocks\data\model\MockImageTag';
public function setUp() {
MockDatabasePost::config();
@@ -1153,6 +1153,36 @@ public function testOn() {
$this->assertEqual($expected, $result);
}
+ public function testWithGeneration() {
+ $model = $this->_gallery;
+
+ $options = array(
+ 'type' => 'read',
+ 'model' => $model,
+ 'with' => array('Image.ImageTag.Tag')
+ );
+
+ $result = $this->db->read(new Query($options));
+ $expected = 'SELECT * FROM {mock_gallery} AS {Gallery} LEFT JOIN {mock_image} AS {Image} ';
+ $expected .= 'ON {Gallery}.{id} = {Image}.{gallery_id} LEFT JOIN {mock_image_tag} AS ';
+ $expected .= '{ImageTag} ON {Image}.{id} = {ImageTag}.{image_id} LEFT JOIN {mock_tag} ';
+ $expected .= 'AS {Tag} ON {ImageTag}.{tag_id} = {Tag}.{id};';
+ $this->assertEqual($expected, $this->db->sql);
+
+ $model = $this->_imageTag;
+ $options = array(
+ 'type' => 'read',
+ 'model' => $model,
+ 'with' => array('Image', 'Tag')
+ );
+
+ $result = $this->db->read(new Query($options));
+ $expected = 'SELECT * FROM {mock_image_tag} AS {ImageTag} LEFT JOIN {mock_image} AS ';
+ $expected .= '{Image} ON {ImageTag}.{image_id} = {Image}.{id} LEFT JOIN {mock_tag} AS ';
+ $expected .= '{Tag} ON {ImageTag}.{tag_id} = {Tag}.{id};';
+ $this->assertEqual($expected, $this->db->sql);
+ }
+
public function testWithOptionAndInlineConstraint() {
$model = $this->_gallery;
Something went wrong with that request. Please try again.