0

I'm upgrading a 2-year-old project and need to create more complex model relationships; I'm a little out of my depth.

I had these tables:

  • items
  • addons
  • orders
  • items_addons

Now I've added these tables:

  • orders_items
  • orders_items_addons

I am getting lost in updating my model associations (vis-a-vis brain-to-mush phenomenon), and consequently I can't get Cake to include orders_items_addons in find() operations from OrdersController, independent of how deep recursion is.

I have these associations:

HasAndBelongsToMany

  • Order: Item
  • Item: Order, Addon
  • Addon: Item, OrdersItem

BelongsToMany

  • ItemsAddon: Item, Addon
  • OrdersItem: Order, Item
  • OrdersItemsAddon: OrdersItem, Addon

(I can post the foreign key/classname/join-table info if needed but I'm pretty sure I have these right.)

When executing this $this->Order->find('all'), however, I'd been expecting the key $result['n']['OrderItem'] to exist and it does not, nor is $this->Order->OrderItem a valid magic-method.

Can anyone help me get a handle on this?

Jonline
  • 1,677
  • 2
  • 22
  • 53
  • If I understand what you are asking, I think all you are after is `->find('all')->contain(['orders_items_addons'])` to pull out your associations – yoyoma Mar 22 '16 at 04:10
  • Hrmm, when I try that I get the error `Model "Order" is not associated with model "orders_items_addon"`. – Jonline Mar 22 '16 at 14:08
  • Yeah so u need to check your associations are correct in the model. Sorry on mobile so don't have the link but check the docs for associations – yoyoma Mar 22 '16 at 14:12

0 Answers0