Sorry, didn't read your post all the way through. DOH! (but my advice still stands on model-ising your join table)
I recently developed an e-commerce app where I was adding and removing a lot of form rows for product images/attributes etc and I never thought of using clone (fairly new to jQuery). I guess that would work quite nicely once you work out how to step through the cloned fields and modify their array numbers accordingly. My short answer is I do not have a behaviour (something I should eventually get my head around). In my app I relied on ajax requests which pulled the form fields out of an element. This way I could apply some logic in the controller action if needed to, i.e. limiting the options found based on values already selected. I had a hidden form field which counted the number of related rows in the form and when clicking on a button to add another row I incremented this number and passed it through with my ajax request so my data array would never have conflicting keys. HTH, Paul. On Aug 29, 9:17 am, WebbedIT <p...@webbedit.co.uk> wrote: > As soon as you want extra fields in the join table you should be model- > ising that table. > > - Recipe hasMany ItemRecipe > - Item hasMany ItemRecipe > - ItemRecipe belongsTo Recipe and Item > > This way you can easily work with the extra fields in your join table > and run finds/paginates on it too. > > On Aug 28, 7:51 pm, Mondo <mo...@nodegarden.net> wrote: > > > > > > > > > I have a Recipe, Item, and Units table/model. I have a HABTM > > relationship with Recipe and Item, and I get the default multiple- > > select box when adding/editing Recipe. (am using Bake for everything > > for the most part). The problem is I need to associate quantities and > > units with each Item. > > > Sample of UI I'm hoping for:http://i.stack.imgur.com/Y4T6T.png > > > A big component of it is the ability to add/delete/edit the individual > > items. I imagine looking at the submitted form data, and using some > > jquery and clone would work. But I was wondering if someone already > > created a Behavior perhaps for this already? > > > Current Models (shortened to the relevant stuff, ie removed users/ > > notes/etc): > > > class Item extends AppModel { > > var $name = 'Item'; > > > // id : int > > // name : varchar > > // unit_id : int > > > var $belongsTo = array( > > 'Unit' => array( > > 'className' => 'Unit', > > 'foreignKey' => 'unit_id' > > ), > > ); > > > var $hasAndBelongsToMany = array( > > 'Recipe' => array( > > 'className' => 'Recipe', > > 'joinTable' => 'recipes_items', > > 'foreignKey' => 'item_id', > > 'associationForeignKey' => 'recipe_id', > > ) > > );} > > > . > > > class Recipe extends AppModel { > > var $name = 'recipe'; > > var $displayField = "name"; > > > // id : int > > // name : varchar > > > var $hasAndBelongsToMany = array( > > 'Item' => array( > > 'className' => 'Item', > > 'joinTable' => 'recipes_items', > > 'foreignKey' => 'recipe_id', > > 'associationForeignKey' => 'item_id', > > ) > > ); > > } > > . > > > class RecipesItem extends AppModel { > > var $name = 'RecipesItem'; > > > // id : int > > // quantity : int > > // unit_id : int > > // recipe_id : int > > // item_id : int > > > var $belongsTo = array( > > 'Unit' => array( > > 'className' => 'Unit', > > 'foreignKey' => 'unit_id' > > ), > > 'Recipe' => array( > > 'className' => 'Recipe', > > 'foreignKey' => 'recipe_id' > > ), > > 'Item' => array( > > 'className' => 'Item', > > 'foreignKey' => 'item_id' > > ) > > ); > > > } -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php