Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorsuthern
     

    Here's a quick setup: I have these two models:

    class SpotsTransfers extends ActiveRecord
    {
        var $belongs_to = array('spot','user');
        var $has_many = array('physicals');
    }
    

    and

    class Physical extends ActiveRecord
    {
        var $belongs_to = array("unit", "spot", "SpotsTransfers");
    }
    

    The table SpotsTransfers has columns source_spot_id, dest_spot_id, and qty.
    The table physicals has columns spot_id and qty.

    Every time a SpotsTransfers->save() occurs, I need to put in a new physical for both the source_spot_id and dest_spot_id, updating their qtys to the new qtys.

    I know how to put a 'afterValidation()' function inside the SpotsTransfers model , but once inside that function how do I perform a physical->save()? I'd appreciate any pointers. Thanks! ;-)

    • CommentAuthorsuthern
     

    Ahhhh, I see that something like this:

    function afterValidation()
    {
        // update physicals
        $physical = $this->physical->build();
        // add / update $physical attributes
        $physical->save();
        return true;
    }
    

    should get me well on my way.