Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Allow saving extra columns to junction table #15

Closed
sspat opened this issue Jun 7, 2017 · 0 comments
Closed

Allow saving extra columns to junction table #15

sspat opened this issue Jun 7, 2017 · 0 comments
Milestone

Comments

@sspat
Copy link

sspat commented Jun 7, 2017

Currently it the behavior code it is hard coded that the yii\db\BaseActiveRecord->link method is called without a possible third parameter.

The third parameter is used for passing additional columns data to be saved to the junction table in a many-to-many relationship through a junction table.
http://www.yiiframework.com/doc-2.0/yii-db-baseactiverecord.html#link()-detail

It would be nice if the behavior would allow to pass and save/update such additional columns in the junction table utilizing this native Yii2 method.

For example it could be made with declaring a callback in the behavior configuration that returns an array of the junction table column values for each ActiveRecord instance being saved,

An example:

/** @inheritdoc */
    public function behaviors()
    {
        return [
            'saveRelations' => [
                'class'     => SaveRelationsBehavior::class,
                'relations' => [
                    'photos'
                ],
                'junctionTableProperties' => [
                    'photos' => function (\yii\db\ActiveRecord $record) :array {
                        return [
                            'order' => $record->order
                        ];
                    }
                ]
            ]
        ];
    }
sspat added a commit to sspat/yii2-save-relations-behavior that referenced this issue Jun 7, 2017
sspat added a commit to sspat/yii2-save-relations-behavior that referenced this issue Jun 7, 2017
sspat added a commit to sspat/yii2-save-relations-behavior that referenced this issue Jun 7, 2017
sspat added a commit to sspat/yii2-save-relations-behavior that referenced this issue Jun 9, 2017
…l of all rows in a junction table representing the initial state of a many-to-many relation.

This mode is automatically used if junction table properties are configured for the relation, ensuring that junction table properties are saved even if the related model properties did not change.
feature la-haute-societe#15
sspat added a commit to sspat/yii2-save-relations-behavior that referenced this issue Jun 9, 2017
… not be found on $actualModels generation.
juban pushed a commit that referenced this issue Jun 24, 2017
@juban juban added this to the 1.4.0 milestone Oct 12, 2017
juban pushed a commit that referenced this issue Oct 28, 2017
@juban juban closed this as completed Nov 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants