On 6/26/07, M <[EMAIL PROTECTED]> wrote: > > > Hello, I have the following model to implement, but I do not know how > to do it with CakePhp > > 1) A user has many items > 2) items can be weapons, armours, food. Any different type of items > has a different table, with different attributes (for example, weapons > have damage attributes, armours have armourclass attribute etc etc) > 3) A tipical functionality would be to show all the items a player > has, with all their attributes, Example: > > Mister Z has in its inventory: > > - dagger (4 damage) > - iron helmet (AC: 1) > - a white apple
First up, within your User model, you need something like this. You need to review the section of the manual that talks about hasMany to make sure you have any additional options (especially limit and order) var $hasMany = array( 'Item' => array('className' => 'Item', 'foreignKey' => 'item_id' ) ) Then I think you need to design your Item to use generic terms, and/or contain data structures (hashes, arrays) that don't make reference to the attributes. You probably want to keep a simple single "Item" that you can iterate round, display etc rather than have to write custom output logic for several different types. So when you make a query for a user, you get back an array of Items associated with that user. You can use some simplistic light logic in the view to alter your output if necessary. If written correctly, you should just be able to output the attributes without knowing in advance what they are. If you are just talking about a couple of bytes per field, it might even be worth adding them into the definition of Item, even if they aren't getting used for all Items (especially if not that many). Not normalised, but easy solution. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---