src/Rails/ActiveRecord/Associations/Associations.php
public function callbacks()
    {
        $dependent = false;
        $autosave  = false;
        $callbacks = [
            'beforeDestroy' => [],
            'beforeSave'    => []
        ];
        
        foreach ($this->associations() as $data) {
            switch ($data['type']) {
                case 'belongsTo':
                case 'hasMany':
                case 'hasOne':
                    if (
                        !empty($data['dependent']) &&
                        !$dependent
                    ) {
                        $callbacks = [
                            'beforeDestroy' => [
                                'alterDependencies'
                            ]
                        ];
                    }
                    # Fallthrough
                
                default:
                    if (
                        !empty($data['autosave']) &&
                        !$autosave
                    ) {
                        $callbacks = [
                            'beforeSave' => [
                                'saveDependencies'
                            ]
                        ];
                    }
                    break;
            }
            
            if ($autosave && $dependent) {
                break;
            }
        }
        
        return array_filter($callbacks);
    }
public function callbacks()
    {
        $dependent = false;
        $autosave  = false;
        $callbacks = [
            'beforeDestroy' => [],
            'beforeSave'    => []
        ];
        
        foreach ($this->associations() as $data) {
            switch ($data['type']) {
                case 'belongsTo':
                case 'hasMany':
                case 'hasOne':
                    if (
                        !empty($data['dependent']) &&
                        !$dependent
                    ) {
                        $callbacks = [
                            'beforeDestroy' => [
                                'alterDependencies'
                            ]
                        ];
                    }
                    # Fallthrough
                
                default:
                    if (
                        !empty($data['autosave']) &&
                        !$autosave
                    ) {
                        $callbacks = [
                            'beforeSave' => [
                                'saveDependencies'
                            ]
                        ];
                    }
                    break;
            }
            
            if ($autosave && $dependent) {
                break;
            }
        }
        
        return array_filter($callbacks);
    }
public function callbacks ( ) { $ dependent = false ; $ autosave = false ; $ callbacks = [ 'beforeDestroy' => [ ] , 'beforeSave' => [ ] ] ; foreach ( $ this -> associations ( ) as $ data ) { switch ( $ data [ 'type' ] ) { case 'belongsTo' : case 'hasMany' : case 'hasOne' : if ( ! empty ( $ data [ 'dependent' ] ) && ! $ dependent ) { $ callbacks = [ 'beforeDestroy' => [ 'alterDependencies' ] ] ; } # Fallthrough default : if ( ! empty ( $ data [ 'autosave' ] ) && ! $ autosave ) { $ callbacks = [ 'beforeSave' => [ 'saveDependencies' ] ] ; } break ; } if ( $ autosave && $ dependent ) { break ; } } return array_filter ( $ callbacks ) ; }
If any of the associations has a 'dependent' option, the
before-destroy callback 'alterDependencies' should be called.
That method will take care of executing the proper tasks with
the dependencies according to the options set.
Same with the 'autosave' option.

# TODO: Move this info somewhere else?
The children's 'autosave' option will override the parent's. For example, User has
many posts with 'autosave' => true, and Post belongs to User with 'autosave' => false.
Upon User save, although User set autosave => true for its association, since Post set
autosave to false, the posts won't be automatically saved. This also clarifies that
the 'autosave' option in a child doesn't mean that the parent will be autosaved, rather,
it defines if the child itself will be saved on parent's save.
If the children are set to be saved alongside its parent, and one of the fails to be saved,
the parent will also stay unsaved.

* If the children aren't set to be saved, their attributes, however, are 'reset':

* <pre>
* // User has many posts, autosave: false
* $user = User::find(1);
* $user->posts()[0]->title = 'Some new title'; // Set new title to first post
* $user->name = 'Some new name'; // Edit user so it can be saved
* $user->save(); // User saved successfuly
* $user->posts()[0]->title = 'Old title'; // Posts attributes got reset
* </pre>

@return array
If any of the associations has a dependent option the before - destroy callback alterDependencies should be called . That method will take care of executing the proper tasks with the dependencies according to the options set . Same with the autosave option .