I'm attempting to lay a Cake app over top of a legacy database and I'm
bumping into a problem with a HABTM relationship. I have a
TechnologyIncentive that HABTM EnergySource through a join table (no
model). Here are the specs:

TechnologyIncentive
  public $name     = 'TechnologyIncentive';
  public $useTable = 'incentive__incentive_tech';
  public $primaryKey = 'id';

  public $hasAndBelongsToMany = array(
    'EnergySource' => array(
      'className'             => 'EnergySource',
      'joinTable'             => 'incentive_tech_energy',
      'foreignKey'            => 'incentive__incentive_tech_id', //
incentive_tech_energy.incentive__incentive_tech_id
      'associationForeignKey' => 'incentive_tech_energy_type_id', //
incentive_tech_energy.incentive_tech_energy_type_id
    ),
  );

EnergySource
  public $name       = 'EnergySource';
  public $useTable   = 'incentive_tech_energy_type';
  public $primaryKey = 'incentive_tech_energy_type_id';

  public $hasAndBelongsToMany = array(
    'TechnologyIncentive' => array(
      'className'             => 'TechnologyIncentive',
      'joinTable'             => 'incentive_tech_energy',
      'foreignKey'            => 'incentive_tech_energy_type_id',
      'associationForeignKey' => 'incentive__incentive_tech_id',
    ),
  );

Even when I try a simple find on TechnologyIncentive like this:

    $es = $this->find( 'all', array(
      'conditions' => array( 'TechnologyIncentive.id' => 11703 ),
    ) );

The SQL log shows that the appropriate query was executed and that a
record was returned, but the result array is empty and I get the
following notice:

Undefined index: incentive__incentive_tech_id

If I dig through dbo_source.php for a while, I find that the linking
table (incentive_tech_energy) fields do not include that particular
field. Every other field comes along for the ride, but not that one. I
don't know why it's being left out, but that seems to be why the
result never gets populated.

If anyone knows their way around dbo_source.php and wouldn't mind
helping, I'd love another set of eyes. Could it be that I'm missing
something simple?

Thanks.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to