mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fix issue with HABTM fields
habtm fields were not being correctly being detected.
This commit is contained in:
parent
d6b978c0e8
commit
1743eaa776
2 changed files with 37 additions and 12 deletions
|
@ -304,7 +304,6 @@ class HelperTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $this->Helper->entity());
|
||||
|
||||
$this->assertEquals('HelperTestComment', $this->Helper->model());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -314,7 +313,11 @@ class HelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testSetEntityAssociatedCamelCaseField() {
|
||||
$this->Helper->fieldset = array('HelperTestComment' => array('fields' => array('BigField' => 'something')));
|
||||
$this->Helper->fieldset = array(
|
||||
'HelperTestComment' => array(
|
||||
'fields' => array('BigField' => array('type' => 'integer'))
|
||||
)
|
||||
);
|
||||
$this->Helper->setEntity('HelperTestComment', true);
|
||||
$this->Helper->setEntity('HelperTestComment.BigField');
|
||||
|
||||
|
@ -322,6 +325,25 @@ class HelperTest extends CakeTestCase {
|
|||
$this->assertEquals('BigField', $this->Helper->field());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that multiple fields work when they are camelcase and in fieldset
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetEntityAssociatedCamelCaseFieldHabtmMultiple() {
|
||||
$this->Helper->fieldset = array(
|
||||
'HelperTestComment' => array(
|
||||
'fields' => array('Tag' => array('type' => 'multiple'))
|
||||
)
|
||||
);
|
||||
$this->Helper->setEntity('HelperTestComment', true);
|
||||
$this->Helper->setEntity('Tag');
|
||||
|
||||
$this->assertEquals('Tag', $this->Helper->model());
|
||||
$this->assertEquals('Tag', $this->Helper->field());
|
||||
$this->assertEquals(array('Tag', 'Tag'), $this->Helper->entity());
|
||||
}
|
||||
|
||||
/**
|
||||
* test that 'view' doesn't break things.
|
||||
*
|
||||
|
|
|
@ -454,23 +454,26 @@ class Helper extends Object {
|
|||
|
||||
$this->_association = null;
|
||||
|
||||
// check for associated model.
|
||||
$reversed = array_reverse($parts);
|
||||
foreach ($reversed as $part) {
|
||||
if (empty($this->fieldset[$this->_modelScope]['fields'][$part]) && preg_match('/^[A-Z]/', $part)) {
|
||||
$this->_association = $part;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// habtm models are special
|
||||
if (
|
||||
isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) &&
|
||||
$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple'
|
||||
) {
|
||||
$this->_association = $parts[0];
|
||||
$entity = $parts[0] . '.' . $parts[0];
|
||||
} else {
|
||||
// check for associated model.
|
||||
$reversed = array_reverse($parts);
|
||||
foreach ($reversed as $part) {
|
||||
if (
|
||||
!isset($this->fieldset[$this->_modelScope]['fields'][$part]) &&
|
||||
preg_match('/^[A-Z]/', $part)
|
||||
) {
|
||||
$this->_association = $part;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_entityPath = $entity;
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue