Probably not, because CakePHP is ADO. If you run your view query in an
mysql client it will give  you the same field name as cake was giving
you, after you gave aliases to every field being returned by your view
cake is now placing it properly on the Model's array.

Regards,

On Dec 1, 8:53 pm, "Christoph" <[EMAIL PROTECTED]> wrote:
> > 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.I can confirm that this is what is happening.  
> > I changed my view to be:
>
> CREATE VIEW users_profile_view AS
> SELECT
>   CONCAT( users.id ) AS id,
>   CONCAT( users.username ) AS username,
>   DATE( users.last_login ) as last_login,
>   CONCAT( users.city ) AS city,
>   CONCAT( users.state ) AS state,
>   CONCAT( users.country ) AS country,
>   CONCAT( users.comments ) AS comments,
>   CONCAT( users.theme ) AS theme,
>   SUM( collections.owned ) as pieces_in_inventory
> FROM users
> LEFT OUTER JOIN collections ON collections.user_id = users.id
> GROUP BY users.id;
>
> and now the result is coming out as:
>
> Array
> (
>     [0] => Array
>         (
>             [UsersProfileView] => Array
>                 (
>                     [id] => bob
>                     [username] => bob
>                     [last_login] => 2002-10-18
>                     [city] => bob
>                     [state] => bob
>                     [country] => bob
>                     [comments] => bob
>                     [theme] => bob
>                     [pieces_in_inventory] => 1
>                 )
>
>         )
>   )
>
> So it appears that CakePHP is getting they key name from the underlying
> database view query when it can determine the qualified table name.  In
> general, because of ->query(), I'm not sure that this is really a bug
> and/or something that should be fixed.  However, what I do think needs
> to be looked at is how it's determining the table name.  Above is the
> SQL in creating the query.  Here is the SQL run by cake in querying the
> database view:
>
> 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
>
> Why is CakePHP getting the table name from the underlying view SQL and
> not this query here?  If it did that, it would get the correct key
> name, 'UsersProfileView', and it would allow views to be modeled
> properly w/o having to use the hack illustrated above where function
> calls are used for every field.
>
> Is this something I should submit a bug ticket for?
> 
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to