Ticket #23 (closed enhancement: fixed)
Add possibility to define own method names for using foreign key relationships
| Reported by: | maulin@… | Owned by: | hans |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.3 |
| Component: | Generator | Version: | devel |
| Severity: | trivial | Keywords: | |
| Cc: |
Description (last modified by hans) (diff)
naming of foreignkey relations (ie one:many or many:one relationships) is a little kludgy. It works fine for the usual case, where you are relating to a foreign table that maps to exactly one object. but in many cases, this is not the case. i added a "phpname" attribute to the foreign key in the schema.xml, and then created some wrapper functions in Object.tpl that make them prettier.
example:
old:
<table name="foo"...> <column name="positionId" ...> <column name="groupId" ...> <foreign-key table="code"> <reference local="positionId" foreign="id"/> </foreign-key> <foreign-key table="code"> <reference local="groupId" foreign="id"/> </foreign-key> </table>
setCodeRelatedByPositionId () setCodeRelatedByGroupId ()
with the addition of phpname to foreignkey...
<foreign-key table="code" phpname="position"> <reference local="positionId" foreign="id"/> </foreign-key> <foreign-key table="code" phpname="group"> <reference local="groupId" foreign="id"/> </foreign-key>
now generates:
setPosition() setGroup()
which call the above (ugly named) functions.
pretty easy to add, and makes the api cleaner.
Change History
comment:1 Changed 5 years ago by hans
- Status changed from new to assigned
- Description modified (diff)
comment:2 Changed 5 years ago by david
- Summary changed from enhancement to Add possibility to define own method names for using foreign key relationships
comment:3 Changed 5 years ago by soenke
- Type changed from defect to enhancement
- Milestone changed from 1.2 to 1.3
comment:4 Changed 4 years ago by hans
- Status changed from assigned to closed
- Resolution set to fixed
Fixed in [494] for 1.3 branch of Propel.
Support was added for a phpName and refPhpName attributes in the <foreign-key> element. For example:
<!-- test self-referencing foreign keys and inheritance--> <table name="bookstore_employee"> <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" description="Employee ID number"/> <column name="name" type="VARCHAR" size="32" description="Employee name"/> <column name="job_title" type="VARCHAR" size="32" description="Employee job title"/> <column name="supervisor_id" type="INTEGER" description="Fkey to supervisor."/> <foreign-key foreignTable="bookstore_employee" phpName="Supervisor" refPhpName="Subordinate"> <reference local="supervisor_id" foreign="id"/> </foreign-key> </table>
This is an example from a self-referencing table in bookstore schema.xml.
The phpName attribute affects naming of methods like setSupervisor(), while the refPhpName attribute affects naming of methods that work with the referencing foreign keys -- e.g. addSubordinate(), getSubordinates().
comment:5 Changed 18 months ago by Frank
Owe no man any thing...
-- Romans 13:8
ordina cialis http://compraviagraitalia.com/it/item/cialis.html acquista viagra online http://compraviagraitalia.com/index.html
http://headachetreatment.net/ viagra ordinare adesso http://compraviagraitalia.com/it/item/generic_viagra.html
http://relievepain.org/tramadol-news/index.php?entry=entry090127-135105
This sounds like a very useful addition. Thanks.