Ticket #1304 (closed defect: fixed)

Opened 11 months ago

Last modified 10 months ago

uniqueSlug does not work correctly if "Sluggable" behavior is used as child of "I18n" behavior.

Reported by: Steffen Owned by: romanb
Priority: major Milestone:
Component: Query/Hydration Version: 1.0.0
Severity: Keywords: hydrator i18n sluggable
Cc: Has Test: yes
Status: Pending Core Response Has Patch: no

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

1304TestCase.php (3.0 KB) - added by Steffen 11 months ago.
TestCase? for this issue.

Change History

Changed 11 months ago by Steffen

TestCase? for this issue.

Changed 11 months ago by Steffen

  • has_test set

Added a testcase.

Changed 11 months ago by jwage

  • version changed from 0.11 to 1.0
  • milestone changed from Unknown to 1.0.0-RC1

Changed 11 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [4746]) fixes #1304

Changed 11 months ago by jwage

Thanks for the test case and ticket.

Changed 10 months ago by anonymous

  • milestone New deleted

Milestone New deleted

Note: See TracTickets for help on using tickets.