Code Monkey home page Code Monkey logo

Comments (1)

xadhoom avatar xadhoom commented on September 26, 2024 1

Why not doing in this way? According to the docs before_* actions should stop any other action, if the return is false.
But looking to lib/Model.php this is not enforced.

with this very simple patch, if the before_* callback return false, the action is interrupted.

--- Model.php.orig  2010-03-30 03:58:07.000000000 +0200
+++ Model.php   2010-04-16 14:35:35.000000000 +0200
@@ -726,7 +726,8 @@
            return false;
 
        $table = static::table();
-       $this->invoke_callback('before_create',false);
+       if (!$this->invoke_callback('before_create',false))
+           return false;
 
        if (!($attributes = $this->dirty_attributes()))
            $attributes = $this->attributes;
@@ -791,7 +792,8 @@
            if (empty($pk))
                throw new ActiveRecordException("Cannot update, no primary key defined for: " . get_called_class());
 
-           $this->invoke_callback('before_update',false);
+           if (!$this->invoke_callback('before_update',false))
+               return false;
            $dirty = $this->dirty_attributes();
            static::table()->update($dirty,$pk);
            $this->invoke_callback('after_update',false);
@@ -814,7 +816,9 @@
        if (empty($pk))
            throw new ActiveRecordException("Cannot delete, no primary key defined for: " . get_called_class());
 
-       $this->invoke_callback('before_destroy',false);
+       if (!$this->invoke_callback('before_destroy',false))
+           return false;
+
        static::table()->delete($pk);
        $this->invoke_callback('after_destroy',false);
 

Hope is ok and can help :)

regards,
matteo

from php-activerecord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.