CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.4 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.4
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
      • Association
      • Attribute
      • Behavior
      • Exception
      • Locator
      • Query
      • Rule
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Trait AssociationsNormalizerTrait

Contains methods for parsing the associated tables array that is typically passed to a save operation

Namespace: Cake\ORM

Method Summary

  • _extractAssociations() protected

    Extracts association names from options array, separating them from actual options.

  • _normalizeAssociations() protected

    Returns an array out of the original passed associations list where dot notation is transformed into nested arrays so that they can be parsed by other routines.

  • _shouldExtractAssociations() protected

    Determines if an array should have associations extracted from it.

Method Detail

_extractAssociations() ¶ protected

_extractAssociations(array $options): array

Extracts association names from options array, separating them from actual options.

Uses CakePHP naming conventions to distinguish associations from options:

  • Association names start with uppercase (CamelCase): Users, Articles
  • Special data keys start with underscore: _joinData, _ids (treated as associations)
  • Option keys start with lowercase (camelCase): onlyIds, conditions

This allows the same nested array format as contain():

  • ['Users', 'Comments'] → associations
  • ['Users' => [...], 'Comments'] → associations
  • ['onlyIds' => true, 'validate' => false] → options only
  • ['Users', 'onlyIds' => true] → mixed
Parameters
array $options

The options array that may contain nested associations.

Returns
array

An array with two elements: [associations, options]

_normalizeAssociations() ¶ protected

_normalizeAssociations(array|string $associations): array

Returns an array out of the original passed associations list where dot notation is transformed into nested arrays so that they can be parsed by other routines.

This method now supports the same nested array format as contain(), allowing:

  • Dot notation: ['First.Second']
  • Nested arrays: ['First' => ['Second', 'Third']]
  • Mixed with options: ['First' => ['Second', 'onlyIds' => true]]
Parameters
array|string $associations

The array of included associations.

Returns
array

An array having dot notation transformed into nested arrays

_shouldExtractAssociations() ¶ protected

_shouldExtractAssociations(array $options): bool

Determines if an array should have associations extracted from it.

Returns true if the array appears to be mixing association names with options, or if it contains nested association structures (like contain() format). Returns false for simple arrays that should be kept as-is.

Uses CakePHP naming conventions to detect associations vs options:

  • Association names start with uppercase (CamelCase): Users, Articles
  • Option keys start with lowercase (camelCase): onlyIds, conditions
  • Special data keys start with underscore: _joinData, _ids
Parameters
array $options

The options array to check.

Returns
bool
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs