Skip to content

Commit

Permalink
Exclude ._ids postfixed fieldnames from pluralization
Browse files Browse the repository at this point in the history
As per convention, fieldnames for belongsToMany associations should
be expected to be already in plural form.
  • Loading branch information
ndm2 committed Feb 24, 2015
1 parent 188862b commit 5c8095a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -1170,14 +1170,17 @@ protected function _optionsOptions($fieldName, $options)
return $options;
}

$pluralize = true;
if (substr($fieldName, -5) === '._ids') {
$fieldName = substr($fieldName, 0, -5);
$pluralize = false;
} elseif (substr($fieldName, -3) === '_id') {
$fieldName = substr($fieldName, 0, -3);
}
$fieldName = array_slice(explode('.', $fieldName), -1)[0];

$varName = Inflector::variable(
Inflector::pluralize($fieldName)
$pluralize ? Inflector::pluralize($fieldName) : $fieldName
);
$varOptions = $this->_View->get($varName);
if (!is_array($varOptions) && !($varOptions instanceof Traversable)) {
Expand Down

0 comments on commit 5c8095a

Please sign in to comment.