Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthordanfreak
     
    I did a small app as a test,

    I noticed that if I set for example a links model, where every link belongs to a linkcategory (and then a linkcategory has_many links) when I use script/generate scaffold the expected dropdowns are not created for the fields linkcategory_id in the links table.

    Is this the normal way scaffolds behaves?
    Or does it recognizes associations on the fly?

    Dan
    •  
      CommentAuthorbermi
     

    Dan, Akelos scaffolds does not create view code for associations. It might be too much guessing to know which form field type and columns to show.

    In Akelos you can simply do something like

    <%= collection_select 'link', 'linkcategory', Link.linkcategories, 'id', 'name' %>
    
    • CommentAuthordanfreak
     
    Cheers bermi,

    Should I grab an array containing the id's and titles from the controller and then pass it to the view with your code Bermi?

    Dan
    • CommentAuthorThijs
     

    Hi there,

    The code Bermi gave as an example is a FormOptionsHelper that you can use in the view. It will generate a html <select> list.

    More info on the API pages

    • CommentAuthorThijs
     

    No wait.. for the example above you do need one more thing: the list with linkcategories should be in Link.linkcategories, and for that to work you should have called:

    $this->Link->linkcategory->load();
    

    in your controller.

    Another way to do it is to include a finder in the code in the view:

    <?=$form_options_helper->select('link','linkcategory_id',$linkcategory->collect($linkcategory->find(),'name','id'));?>
    
    • CommentAuthordanfreak
     
    Super,

    cheers thijs!

    I'll check it out!

    What about updating the Wiki with some of these example?

    I can contribute.

    Dan
    • CommentAuthordanfreak
     
    @thijs

    it works like a sharm!

    $this->Link->linkcategory->load();

    loads the model linkcategory just in a specific method of the controller

    to load multiple models for the all controller I used

    var $models = array('link', 'linkcategory');
    • CommentAuthordanfreak
     
    PS: I have quite a few problems in formatting text in this forum: not really used to markdown...
    •  
      CommentAuthorbermi
     

    Dan you can also add the include option on your finders like

    $this->link->find('all', array('include'=>'linkcategories'));
    

    BTW 4 spaces to indent blocks in markdown ;)