Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relationNames and relatedNames tags update #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,32 @@ Common Setup Options for Doctrine 2.0:
{/d:relatedNames}

The generated StoreProduct class will have "category" and "image" properties instead of "storeProductCategory" and "storeProductImage", while the "StoreProductImage" class will have a "product" property instead of "storeProduct".

This tag can also be used on Many to Many tables (in comments as well), to change the relation names used in each of the 2 tables.
For example, on a store_product_category m2m table, having two foreign keys only (store_product_id and store_category_id), we could have the following:

{d:relatedNames}
StoreProduct:Product
StoreCategory:Category
{/d:relatedNames}

This will generate `products` and `categories` collection properties (along with methods for adding and removing items) on each of the two entities.

* `{d:relationNames}oneToManyName:manyToOneName{/d:relationNames}` (applied to ForeignKey)

Overrides `relatedVarNameFormat` and the `relatedNames` tag from above. Useful when one table references another table multiple times, with multiple foreign keys.

The two names should be the desired field names that this relation would be represented by in the two model classes.

For example, considering a Ticket class and a User class. A ticket could reference the User class with two foreign keys: owner_id and assigned_user_id.

On the Tickets table we could use
- `{d:relationNames}Owner:OwnedTickets{/d:relationNames}` on the owner_id foreign key
and
- `{d:relationNames}AssignedUser:AssignedTickets{/d:relationNames}` on the assigned_user_id foreign key
to override the field names, so a Ticket will have `owner` and `assignedUser` fields, while User will have `ownedTickets` and `assignedTickets`.

Ideally these names would be CamelCase. The oneToMany would be singular and the ManyToOne would be plural.

### Doctrine 2.0 Annotation with ZF2 Input Filter Classes

Expand Down
4 changes: 3 additions & 1 deletion lib/Annotation/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Formatter extends BaseFormatter
const CFG_USE_BEHAVIORAL_EXTENSIONS = 'useBehavioralExtensions';

const NAMING_AS_IS = 'as-is';
const NAMING_AS_IS_LCFIRST = 'as-is-lcfirst';
const NAMING_CAMEL_CASE = 'camel-case';
const NAMING_PASCAL_CASE = 'pascal-case';

Expand Down Expand Up @@ -78,6 +79,7 @@ protected function init()
$this->addValidators(array(
static::CFG_NAMING_STRATEGY => new ChoiceValidator(array(
static::NAMING_AS_IS,
static::NAMING_AS_IS_LCFIRST,
static::NAMING_CAMEL_CASE,
static::NAMING_PASCAL_CASE,
)),
Expand Down Expand Up @@ -130,4 +132,4 @@ public function getFileExtension()
{
return 'php';
}
}
}
Loading