Dear All
I'm two days in to CakePHP and am loving it but have now spent all
afternoon tryiong to work out why I can't seem to do an implicit join
between two tables. I'm almost at the point of resorting to good old
SQL but thought I'd check here first to see if someone can tell me
where I've gone wrong. I get the message:
"Warning (512): SQL Error: 1064: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near '.`id` = 'Marker.MarkerScenario.Scenario.id''
at line 1 [CORE\cake\libs\model\datasources\dbo_source.php, line 514]
Query: SELECT `User`.`id`, `User`.`first_name`, `User`.`last_name`,
`User`.`username`, `User`.`created`, `User`.`modified` FROM `users` AS
`User` WHERE `Marker`.`id` = 1 AND
`User`.`ScenarioUser`.`Scenario`.`id` =
'Marker.MarkerScenario.Scenario.id'"
from the viewUsersForMarker below:
<?php
class UsersController extends AppController {
var $name = 'Users';
var $helpers = array('Html', 'Form');
var $uses = array('Marker','User');
function viewUsersForMarker($marker_id = null) {
if (!$marker_id) {
$this->Session->setFlash(__('Invalid Marker.', true));
$this->redirect(array('action'=>'index')); //need to
redirect
somewhere elserlong-term
}
$this->set('users', $this->User->find('all', array('conditions'
=>
array('Marker.id' => $marker_id, 'User.ScenarioUser.Scenario.id' =>
'Marker.MarkerScenario.Scenario.id'))));
}
I'm trying the get the users who are associated with a scenario that
is also associated with the marker identified by $marker_id.
Thank you for looking - classes below:
class Scenario extends AppModel
{
var $name= 'Scenario';
var $hasAndBelongsToMany = array( 'User' =>array('className' =>
'User'),'Administrator' =>array('className' =>
'Administrator'),'Marker' =>array('className' => 'Marker'));
var $hasMany = array( 'ScenarioUser', 'MarkerScenario');
}
class ScenarioUser extends AppModel
{
var $name= 'ScenarioUser';
var $belongsTo = array ('Scenario','User');
var $hasMany = array ('Justification');
var $useTable = "scenarios_users";
}
class MarkerScenario extends AppModel
{
var $name= 'MarkerScenario';
var $belongsTo = array ('Scenario','Marker');
var $useTable = "markers_scenarios";
}
class User extends AppModel
{
var $name= 'User';
var $hasAndBelongsToMany = array( 'Scenario' =>array('className' =>
'Scenario'), 'Marker' =>array('className' => 'Marker'));
var $hasMany = array( 'ScenarioUser' );
}
class Marker extends AppModel
{
var $name= 'Marker';
var $hasAndBelongsToMany = array( 'Scenario' =>array('className' =>
'Scenario'),'User' =>array('className' => 'User'));
var $hasMany = array( 'MarkerScenario');
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---