Skip to content
Permalink
Browse files

Fix matchingData not having type information set.

As part of the refactoring work done to make typecasting lazy and work
with functions the casting around `_matchingData` was accidentally
broken. This adds each attached association to the type map when fields
are selected on a given association.

Refs #8147
  • Loading branch information...
markstory committed Feb 1, 2016
1 parent 4c84d90 commit ae5b1bf59c8641d23cf93e211abaacfa372a6616
@@ -699,14 +699,14 @@ protected function _dispatchBeforeFind($query)
*/
protected function _appendFields($query, $surrogate, $options)
{
$fields = $surrogate->clause('select') ?: $options['fields'];
$target = $this->_targetTable;
$autoFields = $surrogate->autoFields();
if ($query->eagerLoader()->autoFields() === false) {
return;
}
$fields = $surrogate->clause('select') ?: $options['fields'];
$target = $this->_targetTable;
$autoFields = $surrogate->autoFields();
if (empty($fields) && !$autoFields) {
if ($options['includeFields'] && ($fields === null || $fields !== false)) {
$fields = $target->schema()->columns();
@@ -719,6 +719,7 @@ protected function _appendFields($query, $surrogate, $options)
if (!empty($fields)) {
$query->select($query->aliasFields($fields, $target->alias()));
$query->addDefaultTypes($target);
}
}
@@ -170,6 +170,12 @@ public function testAttachTo()
]
];
$this->assertEquals($expected, $query->clause('join'));
$this->assertEquals(
'integer',
$query->typeMap()->type('Companies__id'),
'Associations should map types.'
);
}
/**
@@ -125,6 +125,12 @@ public function testAttachTo()
'Profiles__user_id' => 'Profiles.user_id'
]);
$association->attachTo($query);
$this->assertEquals(
'string',
$query->typeMap()->type('Profiles__first_name'),
'Associations should map types.'
);
}
/**
@@ -95,8 +95,6 @@ public function setUp()
$orders->hasOne('stuff');
$stuff->belongsTo('stuffTypes');
$companies->belongsTo('categories');
$this->fooTypeMap = new TypeMap(['foo.id' => 'integer', 'id' => 'integer']);
}
/**
@@ -680,15 +678,37 @@ public function testFilteringByHasManyNoHydration()
'user_id' => 4,
'comment' => 'Second Comment for First Article',
'published' => 'Y',
'created' => '2007-03-18 10:47:23',
'updated' => '2007-03-18 10:49:31',
'created' => new Time('2007-03-18 10:47:23'),
'updated' => new Time('2007-03-18 10:49:31'),
]
]
]
];
$this->assertEquals($expected, $results);
}
/**
* Tests that tables results can be filtered by the result of a HasMany
*
* @return void
*/
public function testFilteringByHasManyHydration()
{
$table = TableRegistry::get('Articles');
$query = new Query($this->connection, $table);
$table->hasMany('Comments');
$result = $query->repository($table)
->matching('Comments', function ($q) {
return $q->where(['Comments.user_id' => 4]);
})
->first();
$this->assertInstanceOf('Cake\ORM\Entity', $result);
$this->assertInstanceOf('Cake\ORM\Entity', $result->_matchingData['Comments']);
$this->assertInternalType('integer', $result->_matchingData['Comments']->id);
$this->assertInstanceOf('Cake\I18n\Time', $result->_matchingData['Comments']->created);
}
/**
* Tests that BelongsToMany associations are correctly eager loaded.
* Also that the query object passes the correct parent model keys to the
@@ -2389,6 +2409,20 @@ public function testDebugInfo()
'authors__name' => 'string',
'authors.name' => 'string',
'name' => 'string',
'articles__id' => 'integer',
'articles.id' => 'integer',
'articles__author_id' => 'integer',
'articles.author_id' => 'integer',
'author_id' => 'integer',
'articles__title' => 'string',
'articles.title' => 'string',
'title' => 'string',
'articles__body' => 'text',
'articles.body' => 'text',
'body' => 'text',
'articles__published' => 'string',
'articles.published' => 'string',
'published' => 'string',
],
'decorators' => 0,
'executed' => false,
@@ -3200,6 +3234,6 @@ public function testNotMatchingNested()
]
]
];
$this->assertEquals($expected, $results->first());
$this->assertSame($expected, $results->first());
}
}

0 comments on commit ae5b1bf

Please sign in to comment.
You can’t perform that action at this time.