patchEntity on belongsToMany relationship advice needed
Can someone advise on patchEntity on a belongsToMany relationship? I have the following code: $creditIntermediary = $this->CreditIntermediaries->patchEntity($creditIntermediary,$this->request->data['credit_intermediary'], [ 'associated' => [ 'CreditIntermediaryTypes' ] ]); The entity, both before and after patching, looks like this: App\Model\Entity\CreditIntermediary Object ( [_properties:protected] => Array ( [id] => 31257 [credit_intermediary_types] => Array ( [0] => App\Model\Entity\CreditIntermediaryType Object ( [_properties:protected] => Array ( [id] => 1 [name] => Dealer [_joinData] => App\Model\Entity\CreditIntermediariesCreditIntermediaryType Object ( [_properties:protected] => Array ( [id] => 337 [credit_intermediary_id] => 31257 [credit_intermediary_type_id] => 1 ) ) ) [1] => App\Model\Entity\CreditIntermediaryType Object ( [_properties:protected] => Array ( [id] => 2 [name] => Broker [_joinData] => App\Model\Entity\CreditIntermediariesCreditIntermediaryType Object ( [_properties:protected] => Array ( [id] => 338 [credit_intermediary_id] => 31257 [credit_intermediary_type_id] => 2 ) ) ) ) ) ) The CreditIntermediaryType data come out of the form as follows, for example: Array ( [credit_intermediary] => Array ( [CreditIntermediaryType] => Array ( [0] => 1 [1] => 2 [2] => 3 ) ) ) However, the problem isn't because of the additional form data item (index[2]); regardless of the number of items returned by the form - the same, fewer, or more - it won't patch. Thanks in advance. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
Re: relationship advice
That sounds like one table too many to me. You can get what you want by doing simple finds, made even easier by using the containable behaviour, IMO. Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 10 Aug 2010, at 11:26, Felix wrote: > Thanks, Jeremy, Andras - I think I've worked it out now, > > I wanted to keep the HABTM relationship so I could easily list all the > products in an order and find all the orders a particular product is > listed in, the HABTM seems the easiest way to do it so I'll leave that > as it is. I've added an additional table to store the quantity and > other info. > > Thanks for your quick replies, > > Felix > > On Aug 9, 6:59 pm, Andras Kende wrote: >> Felix, >> >> for a simple cart not sure if habtm is needed... >> >> could be: >> >> products >> id | name | description | image | price | qty >> >> orders >> id | name | address | grandtotal | tracking | status | >> >> order hasmany orderi_tems >> >> order_items >> id | order_id | product_id | qty | price |etc... >> >> order_items belongsto order , product >> >> Andras Kendehttp://www.kende.com >> >> On Aug 9, 2010, at 12:27 PM, Felix wrote: >> >> >> >>> Hi, I was wondering if anyone can help with a problem I'm having. >> >>> I'm building a simple shopping cart system for which I have two >>> objects >> >>> 1. Product (stores product details - name, cost, SKU, etc.) >> >>> 2. Order (Stores order details - customer address, shipping type, >>> etc.) >> >>> In the database these are joined using the table, orders_products. >> >>> Cake correctly recognises the HABTM relationship between the two, so >>> far so good. >> >>> What I'm now stuck at is how to incorporate a quantity variable. >> >>> Each product in an order must have a quantity but I don't know where >>> to put it, >> >>> I don't think it belongs in the products table or the order table, so >>> the only place I can think of is in the join table (orders_products). >> >>> If I add this field in how would I then set or read its value, seeing >>> as it has no model I don;t know how to address it. >> >>> The join table does show up when baking so I could add one, but I >>> don't know if this would mess up the HABTM between the product and >>> order models, and if it does what relationships I need to define in >>> the relevant models to resolve such issues. >> >>> I may of course be missing something or asking a very stupid question, >>> in which case sorry but could you point out my idiocy! >> >>> Thanks, Felix >> >>> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others >>> with their CakePHP related questions. >> >>> You received this message because you are subscribed to the Google Groups >>> "CakePHP" group. >>> To post to this group, send email to cake-php@googlegroups.com >>> To unsubscribe from this group, send email to >>> cake-php+unsubscr...@googlegroups.com For more options, visit this group >>> athttp://groups.google.com/group/cake-php?hl=en > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > 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?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Re: relationship advice
Thanks, Jeremy, Andras - I think I've worked it out now, I wanted to keep the HABTM relationship so I could easily list all the products in an order and find all the orders a particular product is listed in, the HABTM seems the easiest way to do it so I'll leave that as it is. I've added an additional table to store the quantity and other info. Thanks for your quick replies, Felix On Aug 9, 6:59 pm, Andras Kende wrote: > Felix, > > for a simple cart not sure if habtm is needed... > > could be: > > products > id | name | description | image | price | qty > > orders > id | name | address | grandtotal | tracking | status | > > order hasmany orderi_tems > > order_items > id | order_id | product_id | qty | price |etc... > > order_items belongsto order , product > > Andras Kendehttp://www.kende.com > > On Aug 9, 2010, at 12:27 PM, Felix wrote: > > > > > Hi, I was wondering if anyone can help with a problem I'm having. > > > I'm building a simple shopping cart system for which I have two > > objects > > > 1. Product (stores product details - name, cost, SKU, etc.) > > > 2. Order (Stores order details - customer address, shipping type, > > etc.) > > > In the database these are joined using the table, orders_products. > > > Cake correctly recognises the HABTM relationship between the two, so > > far so good. > > > What I'm now stuck at is how to incorporate a quantity variable. > > > Each product in an order must have a quantity but I don't know where > > to put it, > > > I don't think it belongs in the products table or the order table, so > > the only place I can think of is in the join table (orders_products). > > > If I add this field in how would I then set or read its value, seeing > > as it has no model I don;t know how to address it. > > > The join table does show up when baking so I could add one, but I > > don't know if this would mess up the HABTM between the product and > > order models, and if it does what relationships I need to define in > > the relevant models to resolve such issues. > > > I may of course be missing something or asking a very stupid question, > > in which case sorry but could you point out my idiocy! > > > Thanks, Felix > > > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others > > with their CakePHP related questions. > > > You received this message because you are subscribed to the Google Groups > > "CakePHP" group. > > To post to this group, send email to cake-php@googlegroups.com > > To unsubscribe from this group, send email to > > cake-php+unsubscr...@googlegroups.com For more options, visit this group > > athttp://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Re: relationship advice
Felix, for a simple cart not sure if habtm is needed... could be: products id | name | description | image | price | qty orders id | name | address | grandtotal | tracking | status | order hasmany orderi_tems order_items id | order_id | product_id | qty | price |etc... order_items belongsto order , product Andras Kende http://www.kende.com On Aug 9, 2010, at 12:27 PM, Felix wrote: > Hi, I was wondering if anyone can help with a problem I'm having. > > I'm building a simple shopping cart system for which I have two > objects > > 1. Product (stores product details - name, cost, SKU, etc.) > > 2. Order (Stores order details - customer address, shipping type, > etc.) > > In the database these are joined using the table, orders_products. > > Cake correctly recognises the HABTM relationship between the two, so > far so good. > > What I'm now stuck at is how to incorporate a quantity variable. > > Each product in an order must have a quantity but I don't know where > to put it, > > I don't think it belongs in the products table or the order table, so > the only place I can think of is in the join table (orders_products). > > If I add this field in how would I then set or read its value, seeing > as it has no model I don;t know how to address it. > > The join table does show up when baking so I could add one, but I > don't know if this would mess up the HABTM between the product and > order models, and if it does what relationships I need to define in > the relevant models to resolve such issues. > > I may of course be missing something or asking a very stupid question, > in which case sorry but could you point out my idiocy! > > Thanks, Felix > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > 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?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
Re: relationship advice
I'd be tempted to have an order_items table that is not ruled by habtm. Then you can add columns for product_id, quantity, price_charged, tax, dispatched etc. Jeremy Burns Class Outfit jeremybu...@classoutfit.com http://www.classoutfit.com On 9 Aug 2010, at 17:27, Felix wrote: > Hi, I was wondering if anyone can help with a problem I'm having. > > I'm building a simple shopping cart system for which I have two > objects > > 1. Product (stores product details - name, cost, SKU, etc.) > > 2. Order (Stores order details - customer address, shipping type, > etc.) > > In the database these are joined using the table, orders_products. > > Cake correctly recognises the HABTM relationship between the two, so > far so good. > > What I'm now stuck at is how to incorporate a quantity variable. > > Each product in an order must have a quantity but I don't know where > to put it, > > I don't think it belongs in the products table or the order table, so > the only place I can think of is in the join table (orders_products). > > If I add this field in how would I then set or read its value, seeing > as it has no model I don;t know how to address it. > > The join table does show up when baking so I could add one, but I > don't know if this would mess up the HABTM between the product and > order models, and if it does what relationships I need to define in > the relevant models to resolve such issues. > > I may of course be missing something or asking a very stupid question, > in which case sorry but could you point out my idiocy! > > Thanks, Felix > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > 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?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en
relationship advice
Hi, I was wondering if anyone can help with a problem I'm having. I'm building a simple shopping cart system for which I have two objects 1. Product (stores product details - name, cost, SKU, etc.) 2. Order (Stores order details - customer address, shipping type, etc.) In the database these are joined using the table, orders_products. Cake correctly recognises the HABTM relationship between the two, so far so good. What I'm now stuck at is how to incorporate a quantity variable. Each product in an order must have a quantity but I don't know where to put it, I don't think it belongs in the products table or the order table, so the only place I can think of is in the join table (orders_products). If I add this field in how would I then set or read its value, seeing as it has no model I don;t know how to address it. The join table does show up when baking so I could add one, but I don't know if this would mess up the HABTM between the product and order models, and if it does what relationships I need to define in the relevant models to resolve such issues. I may of course be missing something or asking a very stupid question, in which case sorry but could you point out my idiocy! Thanks, Felix Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com 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?hl=en