Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthordanfreak
    • CommentTimeFeb 18th 2008
     
    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
    • CommentTimeFeb 18th 2008 edited
     

    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
    • CommentTimeFeb 18th 2008
     
    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
    • CommentTimeFeb 18th 2008
     

    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
    • CommentTimeFeb 18th 2008 edited
     

    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
    • CommentTimeFeb 18th 2008
     
    Super,

    cheers thijs!

    I'll check it out!

    What about updating the Wiki with some of these example?

    I can contribute.

    Dan
    • CommentAuthordanfreak
    • CommentTimeFeb 18th 2008 edited
     
    @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
    • CommentTimeFeb 18th 2008
     
    PS: I have quite a few problems in formatting text in this forum: not really used to markdown...
    •  
      CommentAuthorbermi
    • CommentTimeFeb 18th 2008
     

    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 ;)

Add your comments
    Username Password
  • Format comments as