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

Association names plural vs singular #240

Open
dereuromark opened this issue Nov 26, 2023 · 4 comments
Open

Association names plural vs singular #240

dereuromark opened this issue Nov 26, 2023 · 4 comments

Comments

@dereuromark
Copy link
Contributor

The docs are a bit confusing to me
https://github.com/vierge-noire/cakephp-fixture-factories/blob/main/docs/associations.md

They link to https://book.cakephp.org/4/en/orm/associations.html (v4 btw, not v5) - in main.
As in Cake, I would assume all relations to be plural

$this->belongsTo('Authors');

But in this plugin, some things are plural, others are singular.

Shouldnt

ArticleFactory::make()->with('Authors.Address.City.Country', ['name' => 'Kenya'])

be

ArticleFactory::make()->with('Authors.Addresses.Cities.Countries', ['name' => 'Kenya'])

?

At least the contain() and other relation chaining in Cake would work this way, afaik?

@pabloelcolombiano
Copy link
Collaborator

The first parameter in ->with() should be the name of the association as defined in the models.

Weither the association is plural or not depends on the association name.

If Cities has one Countries, then CityFactory::make()->with('Countries');

@pabloelcolombiano
Copy link
Collaborator

Under HasOne Associations there are examples where asociations are singular, like HomeAddress.

I think it is ok to leave the examples as such, mixed plural and singular.

@dereuromark
Copy link
Contributor Author

Yeah, the Cake docs are bit confusing here.
Usually the relation is always plural still, so I thought this could be a bit confusing.

$this->belongsTo('Countries', [
    'propertyName' => 'country'
]);

I opened a PR for discussion as this shouldnt be the case in default docs and conventions:
cakephp/docs#7776

@dereuromark
Copy link
Contributor Author

dereuromark commented Nov 29, 2023

The 5.x docs have been fixed up to be consistent: https://book.cakephp.org/5/en/orm/associations.html#hasone-associations

Feel free to close if you wanna keep things as they are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants