Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9179337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:46:16+00:00 2026-06-17T17:46:16+00:00

I’m having a hard time with this CakePHP model/controller development. I have a Product

  • 0

I’m having a hard time with this CakePHP model/controller development.

I have a Product model. The model hasMany pricing, images, videos, content tabs etc.

The model also needs to have many relationships to other products. – eg. accessories, kits, sub-products (variant models of a parent)

So I had created a products_products table where i have a product_id and a related_id – the id of the related accessory/kit or sub product – plus the relationship type.

Table looks like: id,product_id,related_id,type,sort…

My challenge is this – when I load a main product, I want to get all the associated model data for the product which it is related – so, treat the related model like it’s it’s own product (which it is) and load all associated model data

I can load data from the related table easy enough using HABTM relationship .. but simply knowing that the product is related doesn’t give me it’s product model data – pricing, videos, images, promotions, etc etc .

So what’s the best way to develop and load this model? can I do it with standard associated model relationships or do I need to use the main product model to get to my related items, using a list of product ids from the related products_products table using a subquery (which seems very un-Cake like)

? I’d appreciate any input from experienced cake guys.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:46:18+00:00Added an answer on June 17, 2026 at 5:46 pm

    You can save yourself a lot of headaches by using self associations.

    Essentially, you’ll need to create a parent_id field in your Product model, and products with accessories and the like will have the id of the main product in the parent_id field. This will simplify getting the products out the database as you can just call find(‘threaded’).

    From there, it would be easy to set up hasMany relationships for tables holding video/image data about a product.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I am using JSon response to parse title,date content and thumbnail images and place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.