I have two models that I am only using for testing so that I can
understand something else within CakePHP, I realize this example is
not normalized, but the query itself could very well be used in a
production example; I was just unable to think of one before I started
testing.

Models: League, Site

League contains: id (int), name (varchar), site_id (int)
Site contains: id (int), name (varchar), url (varchar)

I want to query and find all League names that also have the same Site
name.
League belongsTo Site.
Site hasOne League.

I am working from the League controller.  teknoid suggested I remove
the foreignKey constraint from the League model (unbind, then rebind
with new setting) which got me closer, but my condition is still not
working.

$conditions = array('League.name' => 'Site.name');
$this->League->find('all', array('conditions' => $conditions));

This results in the following:
SELECT `League`.`id`, `League`.`name`, `League`.`site_id`,
`Site`.`id`, `Site`.`name`, `Site`.`url` FROM `leagues` AS `League`
LEFT JOIN `sites` AS `Site` ON (1 = 1) WHERE `League`.`name` =
'Site.name'

The 'Site.name' is a string, but should be formed as `Site`.`name`
instead, and I can't seem to get CakePHP to modify that data as such.
When I tried placing the condition in the temporary bindModel instead,
the query did not work at all, and the 2nd value is still in a string:
SELECT `League`.`id`, `League`.`name`, `League`.`site_id`,
`Site`.`id`, `Site`.`name`, `Site`.`url` FROM `leagues` AS `League`
LEFT JOIN `sites` AS `Site` ON (`League`.`name` = 'Site.name') WHERE 1
= 1

Does anyone know if it's possible to get Cake to recognize a query
like this?

(For anyone curious, I'm trying to create a Behavior and I just want
to understand how Cake handles this type of query, thus the test.)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to