cakephp-fixture-factories
cakephp-fixture-factories copied to clipboard
Association names plural vs singular
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?
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');
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.
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
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.