mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 11:02:40 +00:00
Fix incorrect field detection for habtm fields.
Fields on habtm models would always be treated as multiselects. Even when there were additional fields specified. Fixes #2153
This commit is contained in:
parent
5efddd11c8
commit
c2c63d373c
3 changed files with 31 additions and 29 deletions
|
@ -453,21 +453,21 @@ class Helper extends Object {
|
|||
|
||||
$this->_association = null;
|
||||
|
||||
// habtm models are special
|
||||
if (
|
||||
$isHabtm = (
|
||||
isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) &&
|
||||
$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple'
|
||||
) {
|
||||
$this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple' &&
|
||||
$count == 1
|
||||
);
|
||||
|
||||
// habtm models are special
|
||||
if ($count == 1 && $isHabtm) {
|
||||
$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)
|
||||
) {
|
||||
foreach ($reversed as $i => $part) {
|
||||
if ($i > 0 && preg_match('/^[A-Z]/', $part)) {
|
||||
$this->_association = $part;
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue