Allowing spaces as part of the inner field declaration, fixes #4690

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6964 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-05-19 12:04:41 +00:00
parent 3a77f6abc8
commit 1448d95478
2 changed files with 19 additions and 1 deletions

View file

@ -278,7 +278,7 @@ class ContainableBehavior extends ModelBehavior {
$option = 'fields';
$val = array($key);
if ($key{0} == '(') {
$val = preg_split('/\s?,/', substr(substr($key, 1), 0, -1));
$val = preg_split('/\s*,\s*/', substr(substr($key, 1), 0, -1));
} elseif (preg_match('/ASC|DESC$/', $key)) {
$option = 'order';
$val = $Model->{$name}->alias.'.'.$key;

View file

@ -2738,6 +2738,24 @@ class ContainableTest extends CakeTestCase {
$this->__assertBindings($this->User->ArticleFeatured->Featured, array('belongsTo' => array('ArticleFeatured', 'Category')));
$this->__assertBindings($this->User->ArticleFeatured->Comment, array('belongsTo' => array('Article', 'User'), 'hasOne' => array('Attachment')));
}
function testEmbeddedFindFields() {
$result = $this->Article->find('all', array('contain' => array('User(user)'), 'fields' => array('title')));
$expected = array(
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
);
$this->assertEqual($result, $expected);
$result = $this->Article->find('all', array('contain' => array('User(id, user)'), 'fields' => array('title')));
$expected = array(
array('Article' => array('title' => 'First Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
array('Article' => array('title' => 'Second Article'), 'User' => array('user' => 'larry', 'id' => 3)),
array('Article' => array('title' => 'Third Article'), 'User' => array('user' => 'mariano', 'id' => 1)),
);
$this->assertEqual($result, $expected);
}
function testFindConditionalBinding() {
$this->Article->contain(array('User(user)', 'Tag' => array('fields' => array('tag', 'created'), 'conditions' => array('created' => '>= 2007-03-18 12:24'))));