Re: Pagination $this->Model->query()
Maybe you're right. But even I can't make silimar cakephp find method to my own sql code. For example: If I use brian's code above I got error: Unknown column 'ItemContent.language_id' in 'where clause'. It's because table ItemContent is just used at 2. query. And I do not know how to set conditions for other queries then just at first one. On Aug 17, 10:13 pm, Miles J wrote: > The funny thing is, 2 queries compared to 1 doesn't make a difference. > You have a problem when you are reaching 1000 queries. I honestly > don't see a problem with a few extra queries as it doesn't really > cause a performance problem. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Pagination $this->Model->query()
The funny thing is, 2 queries compared to 1 doesn't make a difference. You have a problem when you are reaching 1000 queries. I honestly don't see a problem with a few extra queries as it doesn't really cause a performance problem. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Pagination $this->Model->query()
I need to use my own sql code, because if I use your code for find it will do 2 queries and it'll take more time. But thank you for that link, it may be useful for me. On Aug 17, 2:45 am, brian wrote: > Use paginate(). Obviously, that's not the answer you were looking for > but the long and the short of it is that Cake uses paginate() for > pagination. Try this query: > > $items = $this->Item->find( > 'all', > array( > 'conditions' => array( > 'ItemContent.language_id' => $this->language_id > ), > 'fields' => array( > 'Item.id', > 'Item.thumb', > 'Item.module_id' > ) > 'group' => array('Item.id'), > 'contain' => array( > 'ItemContent' => array( > 'fields' => array( > 'ItemContent.name', > 'ItemContent.description', > 'ItemContent.item_id' > ) > ), > 'Module' => array( > 'fields' => array( > 'Module.code' > ) > ) > ) > ) > ); > > You'll need to update your model associations by adding 'type' => > 'INNER'. If that works, it should be simple enough to use paginate(). > Just leave out the condition array and add it within the action: > > $this=>paginate['conditions'] = array('ItemContent.language_id' => > $this->language_id); > > The reason for that is you can use $this->language_id when defining a > class variable. > > If you can't figure out how to turn your query() into a Cake find(), > you could look into using PEAR::pager as a vendor. I've used it before > (though not with a Cake app) and it works quite well. > > http://www.alberton.info/pear_pager_tutorial_article_pagination.html > > On Sun, Aug 16, 2009 at 5:45 PM, gjofum wrote: > > > I'd like to paginate $this->Model->query(). > > > For example I have this in my controller: > > $this->Item->query("SELECT Item.id, Item.thumb, ItemContent.name, > > ItemContent.description, Module.code FROM items AS Item INNER JOIN > > items_content AS ItemContent ON ItemContent.item_id = Item.id INNER > > JOIN modules AS Module ON Module.id = Item.module_id WHERE > > ItemContent.language_id = $this->language_id GROUP BY Item.id"); > > > Sometimes I need to use my own SQL code, because it's faster and > > sometimes I use tables that they don't have relations between them. > > But I don't to how to paginate it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Pagination $this->Model->query()
Use paginate(). Obviously, that's not the answer you were looking for but the long and the short of it is that Cake uses paginate() for pagination. Try this query: $items = $this->Item->find( 'all', array( 'conditions' => array( 'ItemContent.language_id' => $this->language_id ), 'fields' => array( 'Item.id', 'Item.thumb', 'Item.module_id' ) 'group' => array('Item.id'), 'contain' => array( 'ItemContent' => array( 'fields' => array( 'ItemContent.name', 'ItemContent.description', 'ItemContent.item_id' ) ), 'Module' => array( 'fields' => array( 'Module.code' ) ) ) ) ); You'll need to update your model associations by adding 'type' => 'INNER'. If that works, it should be simple enough to use paginate(). Just leave out the condition array and add it within the action: $this=>paginate['conditions'] = array('ItemContent.language_id' => $this->language_id); The reason for that is you can use $this->language_id when defining a class variable. If you can't figure out how to turn your query() into a Cake find(), you could look into using PEAR::pager as a vendor. I've used it before (though not with a Cake app) and it works quite well. http://www.alberton.info/pear_pager_tutorial_article_pagination.html On Sun, Aug 16, 2009 at 5:45 PM, gjofum wrote: > > I'd like to paginate $this->Model->query(). > > For example I have this in my controller: > $this->Item->query("SELECT Item.id, Item.thumb, ItemContent.name, > ItemContent.description, Module.code FROM items AS Item INNER JOIN > items_content AS ItemContent ON ItemContent.item_id = Item.id INNER > JOIN modules AS Module ON Module.id = Item.module_id WHERE > ItemContent.language_id = $this->language_id GROUP BY Item.id"); > > Sometimes I need to use my own SQL code, because it's faster and > sometimes I use tables that they don't have relations between them. > But I don't to how to paginate it. > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---