http://book.cakephp.org/view/84/Saving-Related-Model-Data-hasOne-hasMany-belongsTo
On Sep 12, 5:45 am, Furuno <[email protected]> wrote: > Hello. > > Let's say that I want to create an application to manage inventories > in each stores. I have the following tables : > > Table : products > - id > - name > > Table : stores > - id > - name > > Table : inventories > - id > - product_id > - store_id > - qty > > Every time a new product or store is added. The application will need > to create the related inventory data for the new product/store. For > example, if the existing data is : > > === Products === > Shortcake > Longcake > > === Stores === > North > South > > === Inventories === > Shortcake North 10 > Longcake South 5 > ... > > and new product "Mediumcake", then the following data need to be > created : > > === Inventories === > Mediumcake North 0 > Mediumcake South 0 > > With Java, I can solve this by using EJB service (method) that use the > entity manager to add the related data, like : > > public void createProduct(String name) { > // Create new product and persist it > Product product = new Product(null, name); > em.persist(product); > for each(Store store : getAllStores()) { > // Create new inventory with null id > em.persist(new Inventory(null, product.getId(), store.getId > ()); > } > // Save changes to database > em.flush(); > > } > > I wonder how can I do this with CakePHP? > The only method I've figured out to do this is by using standard SQL & > PHP, but there should be a more "elegant" method... > > Thanks before. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
