propelorm/Propel — pull request #342 by msarris (2012-04-24 12:53:16+00:00)
Title: Cross ref setter (generated by addCrossFKSet) should use FK relation name (phpName) in query filter and add methods

Take this schema:

```xml

````

Both the foreign keys have a custom relation name (phpName).

The following code will be generated for the setter (in BaseUser):

```php
public function setMemberThemes(PropelCollection $memberThemes, PropelPDO $con = null)
{
$themeMembers = ThemeMemberQuery::create()
->filterByTheme($memberThemes)
->filterByMemberUser($this)
->find($con);

$this->memberThemesScheduledForDeletion = $this->getThemeMembers()->diff($themeMembers);
$this->collThemeMembers = $themeMembers;

foreach ($memberThemes as $memberTheme) {
// Fix issue with collection modified by reference
if ($memberTheme->isNew()) {
$this->doAddTheme($memberTheme);
} else {
$this->addTheme($memberTheme);
}
}

$this->collMemberThemes = $memberThemes;
}
```

Note that the filterByTheme, doAddTheme, and addTheme methods do not exist. Instead what should be in their place is filterByMemberTheme, doAddMemberTheme, and addMemberTheme (due to the custom relation name on the FK).

Also note that there is no check if the provided Theme ($memberTheme) is already linked to the User before adding it. This might or will result in a duplicate key error.

I patched the addCrossFKSet in PHP5ObjectBuilder (generator/lib/builder/om/PHP5ObjectBuilder.php) to fix these problems. I hope it will help you.