> Have you checked this issue?
> https://trac.cakephp.org/ticket/845
> Could be related as I see you are using an aggregator function on your SQL
> view.
Hmmm, after looking at it, you would think that these issues may be
related. However, I just confirmed that they are not. There is
definitely something weird about how CakePHP handles database views. I
changed my database view to this:
CREATE VIEW users_profile_view AS
SELECT
users.id,
users.username,
DATE( users.last_login ) as last_login,
users.city,
users.state,
users.country,
users.comments,
users.theme,
collections.game_piece_id as pieces_in_inventory
FROM users
LEFT OUTER JOIN collections ON collections.user_id = users.id
GROUP BY users.id;
N.B., there is only 1 record in the collections table so I figured the
above would be a close approximation of the aggregate. Again, here is
the query executed by CakePHP:
SELECT `UsersProfileView`.`id`, `UsersProfileView`.`username`,
`UsersProfileView`.`last_login`, `UsersProfileView`.`city`,
`UsersProfileView`.`state`, `UsersProfileView`.`country`,
`UsersProfileView`.`comments`, `UsersProfileView`.`theme`,
`UsersProfileView`.`pieces_in_inventory` FROM `users_profile_view` AS
`UsersProfileView` WHERE 1 = 1 LIMIT 5
Here is what was returned on line 555 of dbo_source.php:
Array
(
[0] => Array
(
[users] => Array
(
[id] => joe
[username] => joe
[city] => joe
[state] => joe
[country] => joe
[comments] => joe
[theme] => joe
)
[UsersProfileView] => Array
(
[last_login] => 2002-10-18
)
[collections] => Array
(
[pieces_in_inventory] => 1
)
)
[1] => Array
(
[users] => Array
(
[id] => bob
[username] => bob
[city] => bob
[state] => bob
[country] => bob
[comments] => bob
[theme] => bob
)
[UsersProfileView] => Array
(
[last_login] => 2001-02-16
)
[collections] => Array
(
[pieces_in_inventory] =>
)
)
)
As you can see, now it's adding a 'collections' key. It definitely
seems to me that this is a bug but I can't say for sure because I'm not
overly familiar with the internals of CakePHP and how it handles the
models. I'm wondering if someone who is more familiar could test this
and see if that's the case? If so, I can enter a bug ticket.
To a CakePHP noobie eye, it appears that what's happening is that
CakePHP is getting the key name from the underlying view query or
something. Because if you look at the view, 'pieces_in_inventory' is
using the qualified table name (collections) as are the other fields in
the users table with the exception of 'last_login'. I think in that
case, the function call to DATE() is throwing CakePHP off. Because it
can't determine the table name, it defaults to the model name. This
could explain why 'pieces_in_inventory' was a value in the
'UsersProfileView' array previously. The SUM() function call threw
CakePHP off and because it couldn't determine the table name, it just
defaulted to the model name.
Now, if that's true, I'm curious why CakePHP doesn't just use the model
name in all cases? But I suppose the answer to that lay in the fact
that it also supports plain jane SQL queries using ->query(). So I'm
wondering if that is the case, where does that leave database views?
It seems like it won't be possible to model them afterall...?
thnx,
Christoph
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---