Re: Using ORM Entity mutators to change value doesn't work
I meant a Type for the JSON data, it could be used for the comma separated values, but not sure that would actually make sense. On Thursday, February 20, 2014 7:41:29 AM UTC+1, bato wrote: > > Do you mean a Type class to tranform spaces in commas and reverse it? Is > it really useful? > > Or do you mean a Type to jsonize, serialize? > Il 14/feb/2014 17:31 "José Lorenzo" > ha > scritto: > >> Thanks, for getting back. Also I realized that I wrote directly to you >> instead of the group. The types system was designed with that in mind, you >> should use it instead of entity getters and setters. I hope to post a few >> examples on that when I get more time. Maybe you can help us writing that >> specific type class and document it, that would be of great help! >> >> >> On Fri, Feb 14, 2014 at 4:04 PM, Alberto Pagliarini >> >> > wrote: >> >>> Thanks José for the answer. >>> >>> Let me know what you decide and if I can help. >>> Anyway my example is born because I often need to save data in different >>> format from original (serialize/unserialize, json_encode, json_decode, >>> etc..) and I think would be cleaver do it with setter and getter. >>> >>> For serialize and json maybe I could use custom Type >>> http://book.cakephp.org/3.0/en/orm/database-basics. >>> html#adding-custom-types but I need to study how it works and for other >>> data manipulation (as in example above) define a custom type would be >>> unsuitable. >>> >>> cheers >>> alberto >>> >>> >>> 2014-02-14 14:48 GMT+01:00 José Lorenzo >>> >: >>> I need to think about this for a bit. The only reason that people seem to be wanting getters in the entity is for doing presentational formatting on the same properties as the database, which was not my original intention. I'll look into a solution for this so it is more intuitive. On Friday, February 14, 2014 11:02:39 AM UTC+1, bato wrote: > > Il giorno venerdì 14 febbraio 2014 01:57:53 UTC+1, mark_story ha > scritto: >> >> One more thing. The orm will use the getter functions when preparing >> the data to be saved. Since your getter reverses te setter. This might >> be >> the source of your problem. >> >> >> Yes, commenting the getter the save works as expected. > But how can I do what I was trying to do? I would expect that saving > use setter but not getter so as I can save some modified data and > retireve > later in the original format. > I.e. > > saving data > original data = 'name surname' => save (use setter) => save on db > 'name,surname' > > retrieving data > saved data on db 'name,surname' => find (use getter) => original data > 'name surname' > > I know I could obtain the same results modifing original data before > saving it but I would know if there is a method using ORM properties. > > thanks for your great work > alberto > > >>> >>> >>> -- >>> -- bato --- >>> >>> -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Using ORM Entity mutators to change value doesn't work
Do you mean a Type class to tranform spaces in commas and reverse it? Is it really useful? Or do you mean a Type to jsonize, serialize? Il 14/feb/2014 17:31 "José Lorenzo" ha scritto: > Thanks, for getting back. Also I realized that I wrote directly to you > instead of the group. The types system was designed with that in mind, you > should use it instead of entity getters and setters. I hope to post a few > examples on that when I get more time. Maybe you can help us writing that > specific type class and document it, that would be of great help! > > > On Fri, Feb 14, 2014 at 4:04 PM, Alberto Pagliarini > wrote: > >> Thanks José for the answer. >> >> Let me know what you decide and if I can help. >> Anyway my example is born because I often need to save data in different >> format from original (serialize/unserialize, json_encode, json_decode, >> etc..) and I think would be cleaver do it with setter and getter. >> >> For serialize and json maybe I could use custom Type >> http://book.cakephp.org/3.0/en/orm/database-basics. >> html#adding-custom-types but I need to study how it works and for other >> data manipulation (as in example above) define a custom type would be >> unsuitable. >> >> cheers >> alberto >> >> >> 2014-02-14 14:48 GMT+01:00 José Lorenzo : >> >>> I need to think about this for a bit. The only reason that people seem >>> to be wanting getters in the entity is for doing presentational formatting >>> on the same properties as the database, which was not my original >>> intention. I'll look into a solution for this so it is more intuitive. >>> >>> On Friday, February 14, 2014 11:02:39 AM UTC+1, bato wrote: Il giorno venerdì 14 febbraio 2014 01:57:53 UTC+1, mark_story ha scritto: > > One more thing. The orm will use the getter functions when preparing > the data to be saved. Since your getter reverses te setter. This might be > the source of your problem. > > > Yes, commenting the getter the save works as expected. But how can I do what I was trying to do? I would expect that saving use setter but not getter so as I can save some modified data and retireve later in the original format. I.e. saving data original data = 'name surname' => save (use setter) => save on db 'name,surname' retrieving data saved data on db 'name,surname' => find (use getter) => original data 'name surname' I know I could obtain the same results modifing original data before saving it but I would know if there is a method using ORM properties. thanks for your great work alberto >> >> >> -- >> -- bato --- >> >> -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Using ORM Entity mutators to change value doesn't work
Thanks, for getting back. Also I realized that I wrote directly to you instead of the group. The types system was designed with that in mind, you should use it instead of entity getters and setters. I hope to post a few examples on that when I get more time. Maybe you can help us writing that specific type class and document it, that would be of great help! On Fri, Feb 14, 2014 at 4:04 PM, Alberto Pagliarini wrote: > Thanks José for the answer. > > Let me know what you decide and if I can help. > Anyway my example is born because I often need to save data in different > format from original (serialize/unserialize, json_encode, json_decode, > etc..) and I think would be cleaver do it with setter and getter. > > For serialize and json maybe I could use custom Type > http://book.cakephp.org/3.0/en/orm/database-basics.html#adding-custom-types > but > I need to study how it works and for other data manipulation (as in example > above) define a custom type would be unsuitable. > > cheers > alberto > > > 2014-02-14 14:48 GMT+01:00 José Lorenzo : > >> I need to think about this for a bit. The only reason that people seem to >> be wanting getters in the entity is for doing presentational formatting on >> the same properties as the database, which was not my original intention. >> I'll look into a solution for this so it is more intuitive. >> >> On Friday, February 14, 2014 11:02:39 AM UTC+1, bato wrote: >>> >>> Il giorno venerdì 14 febbraio 2014 01:57:53 UTC+1, mark_story ha scritto: One more thing. The orm will use the getter functions when preparing the data to be saved. Since your getter reverses te setter. This might be the source of your problem. Yes, commenting the getter the save works as expected. >>> But how can I do what I was trying to do? I would expect that saving use >>> setter but not getter so as I can save some modified data and retireve >>> later in the original format. >>> I.e. >>> >>> saving data >>> original data = 'name surname' => save (use setter) => save on db >>> 'name,surname' >>> >>> retrieving data >>> saved data on db 'name,surname' => find (use getter) => original data >>> 'name surname' >>> >>> I know I could obtain the same results modifing original data before >>> saving it but I would know if there is a method using ORM properties. >>> >>> thanks for your great work >>> alberto >>> >>> > > > -- > -- bato --- > > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Re: Using ORM Entity mutators to change value doesn't work
Il giorno venerdì 14 febbraio 2014 01:57:53 UTC+1, mark_story ha scritto: > > One more thing. The orm will use the getter functions when preparing the > data to be saved. Since your getter reverses te setter. This might be the > source of your problem. > > > Yes, commenting the getter the save works as expected. But how can I do what I was trying to do? I would expect that saving use setter but not getter so as I can save some modified data and retireve later in the original format. I.e. saving data original data = 'name surname' => save (use setter) => save on db 'name,surname' retrieving data saved data on db 'name,surname' => find (use getter) => original data 'name surname' I know I could obtain the same results modifing original data before saving it but I would know if there is a method using ORM properties. thanks for your great work alberto -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Using ORM Entity mutators to change value doesn't work
One more thing. The orm will use the getter functions when preparing the data to be saved. Since your getter reverses te setter. This might be the source of your problem. -mark -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Using ORM Entity mutators to change value doesn't work
So I tried to reproduce this and everything worked as expected. The correct data was saved for me. Perhaps double check that your entity class is being used? -mark -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Using ORM Entity mutators to change value doesn't work
Nope that is how they should work. I can take a look tongiht and see if I can reproduce that issue. -mark -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.
Using ORM Entity mutators to change value doesn't work
Hi everyone, I'm very excited wit new CakePHP 3 ORM! Now I'm playing with accessors and mutators but I have issues trying to change the value to save on db. Here is my Entity true]; public function getName($name) { return str_replace(',', ' ', $name); } public function setName($name) { $name = str_replace(' ', ',', $name); return $name; } public function getNameUpper() { return strtoupper($this->_properties['name']); } } Everything works except for Author::setName(). When I save from controller public function saveAuthor() { //debug($this->request->data()); $data = ['name' => 'John Smith']; $authors = TableRegistry::get('Authors'); $author = $authors->newEntity($data); if (!$authors->save($author)) { die("error"); } } setName method is called and return the $name to save but in database the name doesn't reflect the changes done in setName. setName returns 'John,Smith' but in db I have 'John Smith'. Have I misunderstood how mutators work? -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscr...@googlegroups.com. To post to this group, send email to cake-php@googlegroups.com. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/groups/opt_out.