Good observation! I had somehow missed the missing backtick ...
another thing for which I don't understand ... I know it _has_ to be
something subtle, but I just can't get my finger on it ...
Anyway, here are the model classes (I have just removed some of the
option keys from the auto-generated stuff):
user.php:
<?php
class User extends AppModel {
var $name = 'User';
var $validate = array(
'login' => array('alphanumeric'),
'points' => array('numeric')
);
var $hasMany = 'Bid';
var $hasAndBelongsToMany = array(
'BidSession' => array('joinTable' =>
'bid_session_registrations')
);
}
?>
bid_session.php
<?php
class BidSession extends AppModel {
var $name = 'BidSession';
var $validate = array(
'title' => array('alphanumeric'),
'cap' => array('numeric')//,
//'starts_at' => array('date'),
//'ends_at' => array('date')
);
var $hasMany = 'Bid';
var $hasAndBelongsToMany = array(
'User' => array('joinTable' => 'bid_session_registrations')
);
}
?>
bid.php
<?php
class Bid extends AppModel {
var $name = 'Bid';
var $validate = array(
'bid_points' => array('numeric')
);
var $belongsTo = array('User', 'BidSession');
}
?>
It doesn't help even if I specify the 'foreignKey' and
'associationForeignKey' in the HABTM relationship.
As a quick-and-dirty debug, I put the line
pr($query);
in Model::find() [CORE\cake\libs\model\model.php] just before the call
to $db->read($this, $query); on line 1795. This is what I get (url: /
users/add):
Array
(
[conditions] =>
[fields] => Array
(
[0] => BidSessionRegistration.user_id
[1] => BidSessionRegistration.
)
[joins] => Array
(
)
[limit] =>
[offset] =>
[order] => Array
(
[0] =>
)
[page] => 1
[group] =>
[callbacks] => 1
[recursive] => -1
[list] => Array
(
[groupPath] =>
[valuePath] => {n}.BidSessionRegistration.
[keyPath] => {n}.BidSessionRegistration.user_id
)
)
In the docs for Model::find() it's written that:
* Specifying 'fields' for new-notation 'list':
* - If no fields are specified, then 'id' is used for key and 'model-
>displayField' is used for value.
* - If a single field is specified, 'id' is used for key and
specified field is used for value.
* - If three fields are specified, they are used (in order) for key,
value and group.
* - Otherwise, first and second fields are used for key and value.
So I modified the auto-generated $this->User->BidSessionRegistration-
>find('list') call in users_controller.php by explicitly specifying
the fields as array('bid_session_id', 'user_id') ... still, no
improvement.
Now I changed the bid_session_registrations table by removing PK
(bid_session_id, user_id) and adding an id field (although I guess
there's no need to do that for join tables that are not separately
modeled...). Now, the debug output reads:
Array
(
[conditions] =>
[fields] => Array
(
[0] => BidSessionRegistration.id
[1] => BidSessionRegistration.id
)
.
.
.
[list] => Array
(
[groupPath] =>
[valuePath] => {n}.BidSessionRegistration.id
[keyPath] => {n}.BidSessionRegistration.id
)
)
But this is not what I want...
Also, I have no clue why the bake script related User to
BidSessionRegistration not BidSession in /user/add...
Sorry for the long post, but I am really confused why things are
happening the way they are. Thanks for all the help!
On Aug 20, 3:47 am, MonkeyGirl <[EMAIL PROTECTED]> wrote:
> > (a) If I go to /users/add, I get the following SQL error: 1064: You
> > have an error in your SQL syntax; ... near 'bid_session_registrations`
> > AS `BidSessionRegistration` WHERE 1 = 1' at line 1 [CORE\cake\libs
> > \model\datasources\dbo_source.php, line 512]. Query: SELECT
> > `BidSessionRegistration`.`user_id`, BidSessionRegistration`. FROM
> > `bid_session_registrations` AS `BidSessionRegistration` WHERE 1 = 1.
> > Note the missing field name before 'FROM'. This table has PK
> > (bid_session_id, user_id). If I remove that and add an id field as PK,
> > things start working. However, since I am not interested in using this
> > join model directly, I shouldn't have to do this ... as far as I
> > understand from the manual and other cake blogs/tutorials.
>
> What you're doing in general sounds right to me. If that's a straight
> copy-and-paste, note that you're also missing a backtick just before
> the table name that has a missing column. It sounds like CakePHP's
> getting somewhat confused about the table structure. Check for any
> typos or anything slightly askew in the models. Whenever I've had
> similar errors myself, it's usually something subtle but not
> particularly complex. If that doesn't help, maybe pasting the models'
> classes here might shed some light on the problem.
>
> Hope that helps,
> Zoe.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---