Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorsuthern
     
    My setup:
    Parent model: Position
    Child Model: PositionTask

    The PositionTask has fields like 'is_on_all_days', 'is_on_sunday'.....'is_on_saturday'.

    What I'd like to do is $Position->per_day_position_task->load('is_on_'.$day_of_week), and only the child rows with 'is_on_sunday' would be returned. (Obviously depending on what $day_of_week is set to).

    I thought I could do this in the var $models section, but php does not like to include variables when initializing variables.

    Does anyone have a 'Akelos' way for doing the above? :-)
    • CommentAuthorsuthern
     
    Here's what I've come up with. Oh, and I wouldn't mind hearing from ya if you've got a more elegant solution. :-)

    $Position->position_tasks = $Position->position_task->find('all',array('conditions' => array('is_on_all_days = 1 OR is_on_'.strtolower($day_of_week).' = 1')));
    •  
      CommentAuthorbermi
     

    What about

    class Position extends ActiveRecord{
        var $has_many = array(
             'monday_tasks' => array('conditions' => array('is_on_all_days = 1 OR is_on_monday = 1') ),
             'tuesday_tasks' => array('conditions' => array('is_on_all_days = 1 OR is_on_tuesday = 1') ),
             //............
        );
    }
    

    And then you can include the association in the query where you fetch the Position?

    Or loading it like

    $Position->{"{$day_of_week}_tasks"}->load();
    
    • CommentAuthorsuthern
     

    Hey, now that's clever! The only issue I see is that I'd need to do something like this

    $this->Position->position_tasks = $this->Position->{"{$day_of_week}_tasks"}->load();
    

    so that I wouldn't have to make all the downstream code dependent on what day of the week it was.

    You've started me thinking in the right direction though. Thanks!