On 12/1/06, Christoph <[EMAIL PROTECTED]> wrote: > > In my client, whether it's the GUI app developed by MySQL or the > command line, whenever I query (or DESCribe) the view, it all looks > fine. Somehow, for some reason, CakePHP is getting, and using > (erroneously in my opinion) the table names from the underlying view > query and not from the view itself. >
I'm reminded of an old joke: Man goes to the doctor's office. When he sees the doctor, he points to his arm and says "It hurts when I do this." and lifts his arm up over his head. After a thoughtful pause, the doctor says "Then don't do that". *rimshot* I think it's obvious that your expectation of how CakePHP should handle views does not match the currently reality of how CakePHP handles views. Somehow I don't think they had views in mind when they built the Model class. If you do a google search for doing views with ActiveRecord (Rails' ORM wrapper for database) the prevailing wisdom seems to be that you don't need views because you can use all the relationship stuff (belongsTo, hasMany etc) to do that sort of stuff for you. Here's an example: ******* @navinsamuel: thanks for the feedback. Question: Why would you create views? I would say if you need views for other users of your database (and not your applications) then that may be the time to go directly to your db to create them. But if you're staying in Rails and only giving people access to the data through your application there is so much that you can do to join and combine data from multiple tables into objects (or models) that you should never have to. (my next article is going to do some of that!) Rails is full stack which means all tiers of your app are managed through the Rails framework. If that is the case, then a view is largely unnecessary; much like stored procedures are unnecessary in Rails. Rails handles all of that and you can optimize your queries from rails as needed. I will say that there is one database convention that you may want to implement that does not make itself easily known in Rails and that's indexes. You can easily create and drop indexes in Rails to keep those look ups fast. So if I wanted to add an index to the users table on the email field (or is it email_address field at this time? I can't remember) Just do this… add_index(:users, :email) I hope I've answered your question, if not please feel free to provide an example and elaborate on your specific issue. Thanks! ***** It seems to me that trying to stuff a view into the CakePHP model without taking the time to add in code specifically to handle views just isn't going to work, and that you should spend your energy creating an object that will run the view in native SQL and return the data in the format that you need. Is it a bug? Hard to say. When you use a piece of code for something it wasn't intended to do and it doesn't work, is that a bug? Or is that a constraint of that piece of code? I have never used an SQL view and would love to see a real-world example of when a view should be used over, say, the CakePHP model combined with associations. -- Chris Hartjes "The greatest inefficiencies come from solving problems you will never have." -- Rasmus Lerdorf @TheBallpark - http://www.littlehart.net/attheballpark @TheKeyboard - http://www.littlehart.net/atthekeyboard --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
