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

  • Home
  • SEARCH
  • 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 4272738
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:37:05+00:00 2026-05-21T07:37:05+00:00

I’m working with a legacy database whose keys follow a convention, but not the

  • 0

I’m working with a legacy database whose keys follow a convention, but not the cake convention, unfortunately, and I’ve bumped into something odd with the containable behavior — it’s pulling the wrong data. Here’s my setup:

TechnologyIncentive belongsTo...
  array(
    'Incentive' => array(
      'className'  => 'Incentive',
      'type'       => 'inner',
      'foreignKey' => false, # actually 'incentive_id', but we need to fool Cake
      'conditions' => array( 'TechnologyIncentive.incentive_id = Incentive.incentive_id' ),
    ),
    'Technology' => array(
      'className'  => 'Technology',
      'type'       => 'inner',
      'foreignKey' => false, # actually 'incentive_tech_id', but we need to fool Cake
      'conditions' => array( 'TechnologyIncentive.incentive_tech_id = Technology.incentive_tech_id' )
    ),
  );

You can see that I’ve had to fool Cake into working with my non-standard keys by setting the foreignKey to false and defining the link in my where clause. So far so good.

Now, when I try to run a query from the TechnologyIncentive model:

$this->find( 'all', array(
  'contain' => array( 'Incentive', 'Technology' ),
  'fields'  => array( 'Incentive.name', 'Technology.name', 'TechnologyIncentive.amount' ),
  'conditions' => array( /** conditions... */ )
);

Everything works great. Stuff is nicely contained and I get exactly what I’d expect. Then I need to include a TechnologyGroup, which hasMany Technology and things breakdown for some reason.

Now my contain option looks like this:

'contain' => array( 'Incentive', 'Technology' => array( 'TechnologyGroup' ) )

And what I get back is an Incentive record contains an incentive record. That’s not entirely surprising since I’m specifying a few fields in one place (the main fields option) and implicitly all fields in the contain option, but what’s really weird to me is that they’re different incentives. The “contained” incentive is just wrong.

Inspecting the SQL, it looks like the query was run with no effective where clause at all, so everything is being pulled and then artificially limited to a single record. Note the difference between $result['Incentive']['incentive_id'] and $result['Incentive']['Incentive']['incentive_id'].

Array
(
  [Incentive] => Array
    (
      [incentive_id] => MD046
      [name] => Incentive name
      [category] => 
      [Incentive] => Array
        (
          [incentive_id] => AK004
          [code] => AK04F
          [version] => 2
          [category] => Incentive Category
        )

    )
)

Has anyone ever bumped into this? It’s not a problem until I want to retrieve an extended record (TechnologyGroup). Any thoughts would be much appreciated.

  • 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-21T07:37:06+00:00Added an answer on May 21, 2026 at 7:37 am

    It looks like this was directly attributed to the non-standard keys. The Containable behavior, more so, it seems, that other elements of Cake really wants the convention followed. Moreover, some of the key associations included a double underscore (__) in the field name and that caused other problems.

    Kids, don’t try this at home. Follow the conventions, even if it means manipulating a legacy database.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT

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.