Skip to content
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

SoftDeleteQueryBehavior being ignored #5

Open
DiogoAbdalla opened this issue Apr 18, 2019 · 2 comments
Open

SoftDeleteQueryBehavior being ignored #5

DiogoAbdalla opened this issue Apr 18, 2019 · 2 comments

Comments

@DiogoAbdalla
Copy link

DiogoAbdalla commented Apr 18, 2019

Hey, Ive set softdelete behavior in an ActiveRecord model with the following config:

            TimestampBehavior::className(),
            'softDeleteBehavior' => [
                'class'                     => SoftDeleteBehavior::className(),
                'softDeleteAttributeValues' => [
                    'deleted_at' => new Expression('UNIX_TIMESTAMP()')
                ],
                'replaceRegularDelete'      => true
            ],

Its working: when I delete, "detelet_at" is set with the unix timestamp.

Now, to retrieve without the deleted ones, Ive set the query like this:

class UserQuery extends ActiveQuery
{

    public function behaviors()
    {
        return [
            'softDelete' => [
                'class' => SoftDeleteQueryBehavior::className(),
                'deletedCondition'    => [
                    'deleted_at' => new Expression('IS NOT NULL'),
                ],
                'notDeletedCondition' => [
                    'deleted_at' => new Expression('IS NULL'),
                ],
            ],
        ];
    }
}

Its being completely ignored, the deleted records are returned normally on any query

Im not sure its a bug, sorry if it inst. But everything seems right and I dont know what could be wrong.

@cornernote
Copy link
Owner

Can you try this in ActiveQuery class?

public function behaviors() {
    return [
        \cornernote\softdelete\SoftDeleteQueryBehavior::className(),
        // or
        [
            'class' => \cornernote\softdelete\SoftDeleteQueryBehavior::className(),
            'attribute' => 'deleted_time',
        ],
    ];
}

@DiogoAbdalla
Copy link
Author

I just realized Ive posted this on the wrong library (Im actually using yii2tech\ar\softdelete)

Sorry about that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants