Wednesday, February 19, 2014

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" <jose.zap@gmail.com> 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 <batopa@gmail.com> 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 <jose.zap@gmail.com>:
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+unsubscribe@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.

No comments: