Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorklausEC
    First of all, I have 2 questions - 2 things, I have trouble solving right now.
    In my signals_controller, in my update() function, I wish to find certain signals (the ones, I did not just update, that fits with a Meter). This I can do, using:

    $sql = "SELECT * FROM signals WHERE signals.meter_id = $meterid AND signals.id <> $signalID;";
    $signalsToBeUpdated = $this->Signal->findBySql($sql);

    Now I have the signals, I want to update. But how? :P
    I need to set the field "to_be_plottet" to 0, and then save them again.
    Anyone got a good idea?

    This question is related to the first one.
    After the very same update(), I need to do more than just update the other signals - I need to tamper with other tables than just my signals table.
    I have a groups table and a groups_signals table (the many-to-many relation) that I need to insert if not present and update if present. Cannot say in details since I havent thought of them yet :D The main problem is the database access - its against the design principles to make direct data access from the controller, so I am not allowed to alter anthing from here - so... how do I do it?
    add "groups, groups_signals" to $model and use finds on them to reach any present data. if none - i need to insert... again: how? :P
    ... hmm...

    If anyone has got ideas that will help me solve either or both questions, I would welcome them! - A little help please :)
    • CommentAuthorpogeybait4883

    First, do not use findBySQL. You should really get used to using find() instead. I dont have the latest trunk of Akelos so if using references ( =& ) below causes warnings, take out the "&".

    $signals =& $this->Signal->find('all', array( 'conditions' => array( "meter_id=? AND signals.id<>?", $meterid, $signalID) ) ); foreach($signals as $signal) { $signal->to_be_plotted = 0; //change the to_be_plotted to 0 $signal->save(); //save it #look at your groups table for this signal id. Do the same for groups_signals $group =& $this->Group->find('first', array('conditions' => array( "signal_id=?", $signal->id) ) ) if( !empty ( $group ) ) { //if that signal id does not exist, add it $group->signal_id = $signal->id; //set the signal id of this signal $group->save(); //save the group } }

    Hope this helps. It is definitely a step in the right direction for what you want to do. Forgive me if there are any syntax errors or typos.

    • CommentAuthorklausEC

    thank you pogeybait4883 - great help :)