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 713289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:56:40+00:00 2026-05-14T04:56:40+00:00

I have CakePHP app in which I’d like to attach gallery to multiple resources.

  • 0

I have CakePHP app in which I’d like to attach gallery to multiple resources. Let’s say I’ve got artists, each one has own gallery. I’ve got articles, every article has some images attached to it and so on. Now I set up tables like this:

  1. Artists hasMany Artistimages, fields in artistimages table are: id, artist_id, filename, filetype, filesize etc.
  2. Articles hasMany Articleimages, fields in articleimages table are: id, article_id, filename, filetype, filesize etc.

…but this is not how it should be, I think.

Is there possibility to have one table called for example uploads which will contain all images with foreign key pointing to resource its reffering to? How to tell CakePHP which image is coming from which resource?

  • 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-05-14T04:56:40+00:00Added an answer on May 14, 2026 at 4:56 am

    I’d recommend using the Polymorphic Behavior. I often do this for a Binary model which covers images, documents, etc. These represent the physical files that can be associated with any number of models (photos, applicants, etc.).

    The gist of a polymorphic relationship is that the table has 2 additional fields. One field that indicates the name of the model being associated (e.g. Photo, Applicant, etc.) and another for the foreign key value (i.e. the id field in the photos table, for example).

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

Sidebar

Related Questions

I just got this quite large CakePHP app (about 20k lines of code), which
I have a CakePHP app which I have been developing on a remote server.
I have a local cakephp 1.2 app which was working fine last night. Currently
I've got a CAKEPHP app which has the following rewrite rules in the .htaccess
I have built a CakePHP app that creates appointments which have both a client
I have a CakePHP app that is being moved to Sql Server from MySql.
I have a simple cakephp app with table articles that has a cat_id column
I have a cakephp 1.2 app (1.2.2.8120) and I am trying to change the
In my CakePHP 1.2.5 app, I have a Profile model that belongsTo a User
I have a CakePHP Application which I want to protect with a password. The

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.