Ticket #735 (closed defect: fixed)

Opened 18 months ago

Last modified 17 months ago

UniqueValidator peer class discovery

Reported by: jarno Owned by: hans
Priority: normal Milestone:
Component: Runtime (PHP5) Version: 1.3.0
Severity: normal Keywords: validators, unique, peer, class name
Cc:

Description

Setup

I'm using branches/1.3@1107, and I have the following table in my schema.xml:

<table name="prefix_tags" phpName="PrefixTag">
	<column name="tagID" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" />
	<column name="name" type="VARCHAR" size="32" required="true" default="" />
	<column name="createdAt" type="TIMESTAMP" required="true" default="0000-00-00 00:00:00" />
	<unique name="name">
		<unique-column name="name" />
	</unique>
	<validator column="name">
		<rule name="unique" message="Tag with that name already exists" />
		<rule name="match" value="/^\w{2,}$/" message="Tag names must match ${value}" />
	</validator>
</table>

I then add the following to my build.properties:

propel.classPrefix = Prefix

And adjust my schema accordingly:

<table name="prefix_tags" phpName="Tag">
	...
</table>

I get the desired result (my base class is now PrefixBaseTag instead of BasePrefixTag).

Problem

When creating any tags (regardless of whether they exist or not), I get a validation error:

Tag with that name already exists

And I see a warning being emitted:

Warning: call_user_func(TagPeer::doCount) [function.call-user-func]: First argument is expected to be a valid callback in /path/to/project/libs/propel/runtime/classes/propel/validator/UniqueValidator.php on line 55

The relevant lines are:

52: $table = $column->getTable()->getPhpName();
53: 
54: $clazz = $table . 'Peer';
55: $count = call_user_func(array($clazz, 'doCount'), $c);

Proposed solution

The peer class name is being determined by $column->getTable()->getPhpName() which doesn't take the prefixed class name into account.

The following change fixes the behaviour, and works both with code before me adding the prefix and after:

52: $table = $column->getTable()->getClassName();

Attachments

UniqueValidator.php.patch Download (501 bytes) - added by jarno 17 months ago.
Proposed fix for the issue

Change History

Changed 17 months ago by jarno

Proposed fix for the issue

comment:1 Changed 17 months ago by jarno

The current test suite setup makes it just about impossible to write a test reproducing this issue (as it relates to altering the build configuration itself), so Ron and I figured it'll just have to do to ensure no existing tests break.

They don't, so I'll be committing the patch to 1.3 in just a sec.

comment:2 Changed 17 months ago by jarno

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in [1110].

Note: See TracTickets for help on using tickets.