Re: HABTM with non-standard fields
On Sun, Apr 3, 2011 at 7:29 PM, Rob Wilkerson <rob@robwilkerson.org> wrote:
> 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?
>
I suspect the problem is the double underscore. That's jogging my
memory of something in the Cake libs but I can't quite remember where
I saw it.
Gotta love those people who insist on "designing" databases in the
most anally-retentive manner, eh?
--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home