User picture
By on Jul 14, 2009 @ 01:47pm UTC

Behaviors that change data

Hello,

Thanks for the IgnitedRecord. Its been a big help to me. However, I've run into a problem I can't figure out how to get around without editing the core IR classes, which I'd rather not do.

I've created a simple Upload behavior, that lets you handle uploads in a model without having to put in the boiler plate code to handle the uploads and deleting old files on deletes / updates. The behavior doesn't change any of the record's data until the save_pre_insert or save_pre_update hooks.

The problem is that if the only action a user wants to take is update the file information connected to an existing record, IR dies in IgnitedRecord::save() on the check to see if any changes have been made to the data (line 948 of the " IgnitedRecord 1.0 pre_release (rev218)
" download).

Is there some supported way of accomplishing this task in a behavior without changing the IR classes? If not, would you consider changing the classes to allow such behaviors, or would you take patches to do the same?

Thanks in advance,
Pete

User picture
By m4rw3r on Jan 14, 2009 @ 06:21pm UTC

What you can do is to change a property with the save_pre_strip_data, eg. title, then restore it on the save_pre_insert/update hooks:

class someclass{ // may be a behaviour or not, easier with a class, also possible with globals
    var $temp_title;

    function pre_strip_data(&$obj)
    {
        $this->temp_title = $obj->title;
        $obj->title = 'somestrangeandveryuncommonstring';
    }

    function pre_insert(&$data)
    {
         $data['title'] = $this->temp_title;
         // do something
    }
}

The drawback is that this will always update the title column, even if it is unchanged, but it is the best option for now (going to fix the $force option).

 
User picture
By Anonymous on Jan 15, 2009 @ 03:18pm UTC

Thanks, that sounds like a good workable solution!

Are you looking for core contributors?

 
User picture
By Anonymous on May 11, 2009 @ 07:37am UTC

Could you help me. Make hunger thy sauce, as a medicine for health. Help me! There is an urgent need for sites: kitchen islands. I found only this - <a href="http://glass-beads.biz/">Glass halloween beads</a>. Gives any room a dignified feeling with this classic style wall clock. Lowest prices on the net on clocks, wall clocks, mantel clocks and novelty clocks. Thank :rolleyes: Karida from Kazakhstan.

 
User picture
By Anonymous on Jul 09, 2009 @ 11:28pm UTC

Hello. Rest is the sweet sauce of labor. Help me! It has to find sites on the: Free medical billing. I found only this - <a href="http://www.chakrahacker.com/Members/Billing/medical-billing-manager">medical billing manager</a>. Read the medical billing and coding professionals job description and find other. Health care job explosion! Includes a description for the medical billing field. Best regards :-), Maille from Angola.

 
User picture
By Anonymous on Jul 14, 2009 @ 01:47pm UTC

Excuse me. The male is a domestic animal which, if treated with firmness, can be trained to do most things. Help me! There is an urgent need for sites: Dragon comforter sets for boys. I found only this - <a href="http://www.stordtennis.net/Members/Comforter">Comforter set for girls</a>. New lower price! The piece comforter sets include comforter x queen, x king. Comforter sets update your bedroom with the latest trends and colors! The softer toned circle designs on this pc. Best regards :rolleyes:, Donat from Brunei.

 
 

On this conversation: