-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Unify array structure for containing and marshaling associated data #18988
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
base: 6.x
Are you sure you want to change the base?
Conversation
| } | ||
|
|
||
| /** | ||
| * Returns the list of known option keys that should not be treated as associations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I actually prefer the use of the associated key, you don't have to maintain this list of known keys.
How? It seems like only one of them provides the full feature set. The other forms are for 'simple' cases. Maybe we could remove the 'dot notation' form, but I think that is also supported by |
|
Yeah, now they are now equal in support with this. |
|
My issue isn't really with the dot notation. It's with array structure like this where the aliases and config keys can be mixed at the same level: $usersQuery->contain([
'Articles' => [
'conditions' => [.....], // option key
'Comments', // model alias
],
]);I would prefer if the 2nd level associations were also under the config key: $usersQuery->contain([
'Articles' => [
'conditions' => [.....],
'associated' => ['Comments']
],
]); |
|
I can agree that $usersQuery->contain([
'Articles' => [
'conditions' => [.....], // option key
'Comments', // model alias
],
]);is awkward. I'm on-board for not having that anymore. Would it suffice to deprecate only this call style in 5.x? That would allow us to remove the problematic scenario with a graceful upgrade path. It looks like this call style can be detected by having a mix of string and int keys which should be simple enough to detect. I think this also sets us up better for contain options to use a builder pattern more easily in the future. |
|
If aliases were always UpperCaseCamel (upper case first letter), there would also be no collisions. |
I would be happy with just that.
Not always, I think you can have this form too: $usersQuery->contain([
'Articles' => [
'conditions' => [.....], // option as key
'Comments' => [..options for this inner model...] // model alias as key
],
]);
Yes, adding builders in future would be nice. I believe that will also make it easier for AI agents to write CakePHP code.
Yes when naming the aliases as per convention the chances of collision are negligible but it's also about readability. I personally find that this mix of options and alias as same level adds unnecessary cognitive load. |
Resolved conflict in src/ORM/Marshaller.php by keeping both changes: - Documentation for new nested array format (from PR) - Template type annotations (from 6.x) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
So what course do we go? |
|
Is the proposal to check if the isn't isn't one of the allowed option keys and if so suggest using |
|
My main concern would be that this verbose form is super hard to type for default case when u just want list them nested. |
|
Is is annoying. I'm not sure how to improve it with fluid getters other than with a closure - but we already do that to modify the query. |
|
The few times you need to set options, I would in this syntax prefer underscores. We could throw deprecations in 5.x. |
Resolves comments and 6.x roadmap of
#17547
Supported Formats:
But this PR could actually go into 5.next, since it seems "BC".
In 6.x we could then think about removing one of the different declarations.