vierge-noire / cakephp-fixture-factories

CakePHP Fixture Factories
https://vierge-noire.github.io/
MIT License
83 stars 21 forks source link

Association names plural vs singular #240

Open dereuromark opened 9 months ago

dereuromark commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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: https://github.com/cakephp/docs/pull/7776

dereuromark commented 9 months ago

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.