Hi, Chris. You don't have to remove the database relation in order to build your own query.
Take a look at: http://book.cakephp.org/view/73/retrieving-your-data Specifically, look for the query method. Looking at your code I'm afraid it is obvious that you are working too hard. Remember, Cake follows convention over configuration. If you follow certain conventions, you get a lot of functionality for free. Regardless, based on what appears to be a table you have named vw_eventscalendar, yoursetup would be something like the following: <?php class EventCalendar extends AppModel { var $name = 'EventCalendar'; var $useTable = 'vw_eventscalendar'; } ?> a controller <?php App::import('core', 'sanitize'); class EventCalendarsController extends AppController { var $name = 'EventCalendars'; function index() { //now you can iterate over the results of your query in the index view of views/event_calendars/index.ctp $data = $this->EventCalendar->findById('1'); debug($data); $this->set('data', $data); //or, if you wanted to build your own query (if you do always be sure to sanitize any user provided data) //$data = $this->EventCalendar->query('SELECT id, account_id, company_name, event_name, start_date, end_date, lead_name, days_to_event, open_tasks, overdue_tasks FROM vw_eventscalendar WHERE account_id=1'); //debug($data); } } ?> On Mar 4, 12:31 pm, Christopher Hazlett <[EMAIL PROTECTED]> wrote: > I need to base a model on a SQL View so I've set $useTable=false. All > I really want to do is pull this multi-join view from the DB instead > of using the application to try and build a very custom query. Even > though I've set the $useTable variable to false, Cake still looks for > the table underneath (or at least that's what it says it's doing). > > I've attached the model code below. Obviously, It's quite a simple > operation, but it just won't work. > > I'm new to Cake but not PHP, so I may be missing something > fundamental. Any help would be greatly appreciated. > > -Chris > > ---------------------------------------------------------- > class EventCalendar extends AppModel > { > var $name = 'EventCalendar'; > var $useTable = false; > > function index(){ > $this->query('SELECT id, account_id, company_name, event_name, > start_date, end_date, lead_name, days_to_event, open_tasks, > overdue_tasks FROM vw_eventscalendar WHERE account_id=1'); > }} > > ----------------------------------------------------------- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
