Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorsuthern
     
    Manufacturer table has fields id and name.
    Multiplier table as fields manufacture_id and amount.

    Manufacturer model has "$has_many = array('multipliers')".

    In my Manufacturer controller, how can get an array of objects of the multipliers which belong to that manufacturer?
    I've tried $this->manufacturer->multipliers->load(), but Akelos complains that multipliers is not an object.
    I've tried $this->manufacturer->multiplier->load(), and it throws no errors, but the resulting object ($this->manufacturer->multiplier) does not contain any multipliers.

    What is the correct way to load associated records?
    Thanks!
    • CommentAuthorasejua
     

    Hi Suthern,

    You also must tell Multipliers that it belongs to Manufacturer

    in app/models/multiplier.php

    $belongs_to = array('manufacturer');
    

    Then in the manufacturer controller you must set tell the controller to use the multiplier model:

    var $models = 'manufacturer,multiplier';
    

    Then, for each manufacturer, you should do a search like this.

    $this->multipliers =& $this->Multiplier->find('all',array(
    'conditions' => array('_manufacturer.id = '.$this->params['id']),
    'include' => array('manufacturer')));
    

    $this->params['id'] it's the manufacturer id passed by url parameter, for example.

    You could walk $this->multiplier with foreach in your view to get 'em.

    Don't know if this is what you want, but hope it helps as example.

    Regards.

    • CommentAuthorsuthern
     
    Thank you for your help! I know how to normally load a model and then use the ->find() w/ id. What I'm trying to do is use the automatic association.

    It does work the other way. For instance, If I'm looking at it from inside the Multiplier controller, I can do multiplier->manufacturer->load() and it gets the correct parent (and all associated information).

    What I'm trying to do is get all the multipliers that apply to one manufacturer, using only parent->children->load(). If this is not implemented, perhaps I'll put a trac up about it.

    Thanks!
    • CommentAuthorasejua
     

    Hehe, tvw. Guessed that was a too much easy solution and you probably already knew it after reading some of your threads in this forum ;). But well, although I'm still very noob with akelos, the less I can do is try to help a bit :)

    In the other way, I think your last message has given me an idea to solve a problem I'm having with models not directly associated.

    So, thanks to you too!

    • CommentAuthorKaste
     

    after

    $this->manufacturer->multiplier->load()
    
     $this->manufacturer->multipliers
    

    will hold hopefully an array of your records.

    pretty self-explanatory, heh?

    • CommentAuthorsuthern
     
    LOL, I don't feel too awfully smart right now! Ahh, so parent->children is created after calling parent->child. Tested it and yup, it works as expected!

    For some reason I didn't think to check for the plural after calling ->load() on the singular.

    Thanks Kaste! You deserve another free beer!