Ticket #1304 (closed defect: fixed)
uniqueSlug does not work correctly if "Sluggable" behavior is used as child of "I18n" behavior.
Description
I'm using a sample schema like this:
---
SlugI18nTest:
actAs:
I18n:
fields: [title, content]
actAs:
Sluggable:
fields: [title]
columns:
title: string(255)
content: string
If executing the following code
for($i=0; $i<3; $i++) {
$t = new SlugTemplateTest();
$t->Translation['en']->title = 'Title';
$t->Translation['en']->content = 'Content';
$t->save();
echo $t->Translation['en']->slug.'<br/>';
}
the resulting output is
title title-1 title
expected was
title title-1 title-2
I dug a bit through the code, and it seems that in the following code snippet from the "Doctrine_Hydrator" class is causing the problem. The result it returns to the Sluggable template only contains the last slug it found instead of all.
// do we need to index by a custom field?
if ($field = $this->_getCustomIndexField($rootAlias)) {
if (isset($result[$field])) {
throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found non-unique key mapping.");
} else if ( ! isset($element[$field])) {
throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found a non-existent key.");
}
$result[$element[$field]] = $element; /* << here previous results are overwritten */
} else {
$result[] = $element;
}
I also will add a test case.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.