On Jan 29, 10:49 am, CrazyDave <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to do a join that does not depend on a foreign key, but
> uses other clauses that I provide via the conditions attribute.
> Unfortunately I can't seem to get CakePHP to stop adding the
> foreignKey, even when I set it to null, an empty string or false.
>
> Here's the basic idea of what I'm trying to do. I have a news item
> that is tied to a tree structure (using the tree behaviour), I want to
> bring back information about the parent (if it's of a certain type).
>
> var $belongsTo = array(
> 'Structure' => array(
> 'className' => 'Structure',
> 'foreignKey' => 'structure_id'
> ),
> 'parent' => array(
> 'className' => 'Structure',
> 'foreignKey' => false,
> 'conditions' => 'parent.type_id = 1 AND parent.left_id <
> Structure.left_id AND parent.right_id > Structure.right_id'
> )
> );
>
> The query would be perfect if it wasn't for the magically appearing
> "AND `News`.`parent_id` = `parent`.`id`" on the end of the join
> clause. Anyone have any ideas?
Why not use the Tree behavior (and add a parent_id field) with your
model.
If you got your code to work it would find all parents and thus would
not do what you want anyway (and would do exactly the same as the
getPath method in the Tree behavior).
Since you can't belong to more than one X it would need to be a
hasMany to be logically correct or you'd need a parent_id in the table
to find the direct parent - which is part of the reason the Tree
behavior requires you to keep this field as otherwise finding direct
parent/children is difficult/expensive/slow.
hth,
AD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---