Re: Complex Find Conditions
I have no idea. I tried many things and nothing works. For exampple: $this->Item->find("all", array("fields" => array("Item.id", "Item.thumb"), "contain" => array( "ItemContent" => array( "conditions" => array("ItemContent.language_id" => $this- >language_id), "fields" => array( "ItemContent.name", "ItemContent.description", "ItemContent.url"))) )); I'll have to use $this->Model->query() but then I won't be able 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 -~--~~~~--~~--~--~---
Complex Find Conditions
I don't know how to make my own sql code into Complex Find Conditions. Especially with use of INNER JOIN or LEFT INNER. For example: $items = $this->Tag->query("SELECT Item.id, Item.thumb, ItemContent.name, ItemContent.description, ItemContent.url, 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 INNER JOIN items_tags AS ItemTag ON ItemTag.item_id = Item.id WHERE ItemContent.language_id = $this- >language_id AND ItemTag.tag_id = $id AND Item.visible = 0 ORDER BY Item.id DESC"); Please help. --~--~-~--~~~---~--~~ 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()
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()
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 -~--~~~~--~~--~--~---
Pagination $this->Model->query()
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: Update with WHERE Clause
You're right. But I merge 2 tables (in db) together, because retrieving data will be more faster (now i can join only 2 tables, but before I had to join 3 tables, so it's much faster. I will query from this table every page, so speed is more important than saving data for me.) That's why I have id in table but it's not primary key. So inserting is no problem when I have var $cacheQueries = true; in my model. But I can't update it. I have to use in clause WHERE id = ? AND language_id = ? , but I don't know how to do that. On Aug 7, 6:57 am, Jamie wrote: > I'm a bit confused. If you already know the primary key, why do you > need to test for another condition? The primary key is unique, after > all, so logically once you know the ID, you don't need to satisfy any > other 'WHERE' conditions. > > If what you really want to do is ONLY save if language_id = a certain > value, then you can test for that before you save. > > - Jamie > > On Aug 6, 5:02 pm, gjofum wrote: > > > I'd like to update data in db, but I have a problem. > > > If I use $this->...->save(...); it'll only use id (primaryKey) in > > clause WHERE. But I need one more (id = ? and language_id = ? in > > clause WHERE). > > How can I do that? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
primaryKey
I can set up primaryKey in model by variable $primaryKey. But how can I set up that I don't have primaryKey or I don't want it? (Actually I don't want to use primaryKey from my db.) --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Update with WHERE Clause
I'd like to update data in db, but I have a problem. If I use $this->...->save(...); it'll only use id (primaryKey) in clause WHERE. But I need one more (id = ? and language_id = ? in clause WHERE). How can I do that? --~--~-~--~~~---~--~~ 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: Data Validation - What's wrong?
Great. It works. Thank you On Jul 17, 4:03 pm, "rich...@home" wrote: > Should be: > > var $validate = array( > "module_data" => array( > "module_dataRule1" => array( > "rule" => "notEmpty", > "message" => "empty", > "required" => true > ), > "module_dataRule2" => array( > "rule" => array("minLength", 5), > "message" => "min" > ), > "module_dataRule3" => array( > "rule" => array("maxLength", 10), > "message" => "max" > ), > ) > ); > > (note where I've moved 'required' to - it needs to be attached to a > rule) > > On Jul 17, 9:21 am, gjofum wrote: > > > I am setting data a then validate them. > > > $this->Module->set($this->data); > > > if($this->Module->validates()) print "YES"; > > else print "NO"; > > > But I have one more problem. I get 2 errors with just validate rule > > below. > > > Warning (2): preg_match() [function.preg-match]: Delimiter must not be > > alphanumeric or backslash [CORE/cake/libs/model/model.php, line 2431] > > Warning (2): preg_match() [function.preg-match]: Empty regular > > expression [CORE/cake/libs/model/model.php, line 2431] > > > var $validate = array( > > "module_name" => array( > > "required" => true, > > "allowEmpty" => false > > ) > > ); > > > On Jul 17, 10:03 am, Miles J wrote: > > > > Are you setting the data before you validate it, or are you juts > > > calling save()? > > > > $this->Model->set($this->data); --~--~-~--~~~---~--~~ 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: Data Validation - What's wrong?
I am setting data a then validate them. $this->Module->set($this->data); if($this->Module->validates()) print "YES"; else print "NO"; But I have one more problem. I get 2 errors with just validate rule below. Warning (2): preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash [CORE/cake/libs/model/model.php, line 2431] Warning (2): preg_match() [function.preg-match]: Empty regular expression [CORE/cake/libs/model/model.php, line 2431] var $validate = array( "module_name" => array( "required" => true, "allowEmpty" => false ) ); On Jul 17, 10:03 am, Miles J wrote: > Are you setting the data before you validate it, or are you juts > calling save()? > > $this->Model->set($this->data); --~--~-~--~~~---~--~~ 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: Data Validation - What's wrong?
It doesn't help. On Jul 17, 9:58 am, joshua wrote: > Mine: > > > > > 'email' => array( > > 'noEmpty' => array( > > 'rule' => 'email', > > 'allowEmpty' => false, > > 'message' => 'Email can\'t be null' > > ), > > ), > > > > On Fri, Jul 17, 2009 at 3:55 PM, gjofum wrote: > > > I add notEmpty and it still doesn't work. > > > var $validate = array( > > "module_data" => array( > > "module_dataRule1" => array( > > "rule" => "notEmpty", > > "message" => "empty" > > ), > > "module_dataRule2" => array( > > "rule" => array("minLength", 5), > > "message" => "min" > > ), > > "module_dataRule3" => array( > > "rule" => array("maxLength", 10), > > "message" => "max" > > ), > > "required" => true, > > "allowEmpty" => false > > ) > > ); > > > On Jul 15, 11:48 pm, Miles J wrote: > > > You need the "notEmpty" rule. > > -- > Thanks > Joshua > 5span Inc. <https://www.5span.com> --~--~-~--~~~---~--~~ 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: Data Validation - What's wrong?
I add notEmpty and it still doesn't work. var $validate = array( "module_data" => array( "module_dataRule1" => array( "rule" => "notEmpty", "message" => "empty" ), "module_dataRule2" => array( "rule" => array("minLength", 5), "message" => "min" ), "module_dataRule3" => array( "rule" => array("maxLength", 10), "message" => "max" ), "required" => true, "allowEmpty" => false ) ); On Jul 15, 11:48 pm, Miles J wrote: > You need the "notEmpty" rule. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Data Validation - What's wrong?
I have this validate in Model: var $validate = array( "module_data" => array( "module_dataRule1" => array( "rule" => array("minLength", 5), "message" => "min" ), "module_dataRule2" => array( "rule" => array("maxLength", 10), "message" => "max" ), "required" => true, "allowEmpty" => false ) ); And I left empty form for module_data and I get no error. What do I have wrong?? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---