![]() |
|
sfPropelActAsPolymorphicBehaviorPlugin - 0.0.3Enable multi-column foreign keys. |
|
![]() |
2
users
Sign-in
to change your status |
Enable multi-column foreign keys. |
Provides support for multi-column foreign keys.
| Name | Status | |
|---|---|---|
|
|
lead | moc.tcejorp-ynofmys <<ta>> htimsllaw.sirk |
Copyright (c) 2007 Kris Wallsmith
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| Version | License | API | Released |
|---|---|---|---|
| 0.0.3alpha | MIT license | 0.0.3alpha | 25/09/2007 |
| 0.0.2alpha | MIT license | 0.0.2alpha | 16/09/2007 |
The sfPropelActAsPolymorphicBehaviorPlugin is a symfony plugin that provides support for polymorphic keys in Propel objects.
This plugin can be used to store data that each reference a record from any number of tables. For example, you could create one comments table that uses a polymorphic key to reference both the table and the primary key of the foreign record. The example below demonstrates this.
schema.xml.Please post to this forum thread or ping me in the IRC channel (kriswallsmith) if you have any thoughts.
Install the plugin
./symfony plugin-install http://plugins.symfony-project.com/sfPropelActAsPolymorphicBehaviorPlugin
If you haven't already, enable behaviors in propel.ini and rebuild your model.
propel.builder.addBehaviors = true
./symfony propel-build-model
Activate the behavior for one of your Propel models:
[php]
// lib/model/Post.php class Post extends BasePost { }
$hasOneKeys = array('author' => array('foreign_model' => PostPeer::AUTHOR_TYPE, 'foreign_id' => PostPeer::AUTHOR_ID)); $hasManyKeys = array('tags' => array('foreign_model' => TagPeer::SUBJECT_TYPE, 'foreign_id' => TagPeer::SUBJECT_ID), 'comments' => array('foreign_model' => CommentPeer::SUBJECT_TYPE, 'foreign_id' => CommentPeer::SUBJECT_ID)); sfPropelBehavior::add('Post', array('sfPropelActAsPolymorphic' => array('has_one' => $hasOneKeys, 'has_many' => $hasManyKeys))); sfPropelActAsPolymorphicBehavior::mixinCustomMethods('Post');
The call to sfPropelBehavior::add() adds the following methods to your class:
getPolymorphicHasOneReference(string $keyName[Connection $con](,))setPolymorphicHasOneReference(string $keyName, mixed $foreignObject[Connection $con](,))clearPolymorphicHasOneReference(string $keyName[Connection $con](,))getPolymorphicHasManyReferences(string $keyName[Criteria $c[, Connection $con]](,))addPolymorphicHasManyReference(string $keyName, BaseObject $foreignObject[Connection $con](,))clearPolymorphicHasManyReferences(string $keyName[Criteria $c[, bool $doDelete[, Connection $con]]](,))deletePolymorphicHasManyReferences(string $keyName[Criteria $c[, Connection $con]](,))countPolymorphicHasManyReferences(string $keyName[Criteria $c[, bool $distinct[, Connection $con]]](,))Furthermore, calling sfPropelActAsPolymorphicBehavior::mixinCustomMethods() adds a number of custom-named methods to your class, based on the names of your polymorphic keys.
For example, the has_one key author, above, would be accessible with the following methods:
getAuthor([$con](Connection))setAuthor(mixed $foreignObject[Connection $con](,))clearAuthor([$con](Connection))The has_many key tags, above, would be accessible with the following methods:
getTags([$c[, Connection $con]](Criteria))addTags(BaseObject $foreignObject[Connection $con](,)) (this could become addTag() later ... we'll see)clearTags([$c[, bool $doDelete[, Connection $con]]](Criteria))deleteTags([$c[, Connection $con]](Criteria))countTags([$c[, bool $distinct[, Connection $con]]](Criteria))has_many key or setting a has_one key, the foreign object must already be saved. This should be resolved in the next alpha release.Plugin now supports has_many relationships and mixes in custom methods based on the names of your keys.
Initial public release.
setPolymorphicHasOneReference.Kris Wallsmith
