Re: validation of serialized data

2010-02-09 Thread bujanga
Thanks, I will not use serialized data for this. All of my current
contact models use the BelongsTo - HasMany approach and this project
will also. I had just finished coding a metadata interactor and used
serialized data with great success but I see it does not fit for this
type of relationship. The current project is a conversion where the
previous db has 4 fields for emails and 4 fields for phones. Guess
I'll finally have to write my record status behavior.

Gary

2010/2/9 Dérico Filho :
> Unless you really know what you are doing, you should avoid storing
> canonical data in serialized strings.
>
> Though it has been done with very great results off the cakephp world.
>
> See how it is done at FriendFeeder:
> http://bret.appspot.com/entry/how-friendfeed-uses-mysql
>
> Serialized data used as a denormalized data store.
>
> On Feb 8, 6:12 pm, bujanga  wrote:
>> Just some thinking and a question or two, please tell me if I am
>> totally off base.
>>
>> I would like to store multiple email addresses and phone numbers per
>> user. Using a serialized field might work for this. Is that a good
>> usage?
>>
>> Next, how does one validate the data and properly save and find the
>> data. Here is what I am thinking (not tested).
>>
>> Validate the Model using a custom validation function:
>>
>> var $validate = array(
>>         'emails'        => array(
>>                 'is_email'      => array(
>>                         'rule' => array('g_isEmail'),
>>                         'required'              => TRUE,
>>                         'allowEmpty'    => FALSE,
>>                         'message' => 'You must enter at least 1 valid email 
>> address'
>>                 ),
>>         ),
>> )
>>
>> function g_isEmail($check){
>>         if ( !isset($this->data['Model']['emails']) ){
>>                 return FALSE;
>>         }
>>         if ( is_array($this->data['Model']['emails']) ){
>>                 foreach( $this->data['Model']['emails'] as $email ){
>>                         if ( !Validate::email($email) )
>>                                 return FALSE;
>>                         }
>>                 }
>>         }elseif( !Validate::email($this->data['Model']['emails']) )
>>                 return FALSE;
>>         }
>>         return TRUE;
>>
>> }
>>
>> Then using beforeSave to serialize the field and afterFind to
>> unserialize the field.
>>
>> Thanks,
>>
>> Gary Dalton
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
>
> 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
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: validation of serialized data

2010-02-09 Thread Dérico Filho
Unless you really know what you are doing, you should avoid storing
canonical data in serialized strings.

Though it has been done with very great results off the cakephp world.

See how it is done at FriendFeeder:
http://bret.appspot.com/entry/how-friendfeed-uses-mysql

Serialized data used as a denormalized data store.

On Feb 8, 6:12 pm, bujanga  wrote:
> Just some thinking and a question or two, please tell me if I am
> totally off base.
>
> I would like to store multiple email addresses and phone numbers per
> user. Using a serialized field might work for this. Is that a good
> usage?
>
> Next, how does one validate the data and properly save and find the
> data. Here is what I am thinking (not tested).
>
> Validate the Model using a custom validation function:
>
> var $validate = array(
>         'emails'        => array(
>                 'is_email'      => array(
>                         'rule' => array('g_isEmail'),
>                         'required'              => TRUE,
>                         'allowEmpty'    => FALSE,
>                         'message' => 'You must enter at least 1 valid email 
> address'
>                 ),
>         ),
> )
>
> function g_isEmail($check){
>         if ( !isset($this->data['Model']['emails']) ){
>                 return FALSE;
>         }
>         if ( is_array($this->data['Model']['emails']) ){
>                 foreach( $this->data['Model']['emails'] as $email ){
>                         if ( !Validate::email($email) )
>                                 return FALSE;
>                         }
>                 }
>         }elseif( !Validate::email($this->data['Model']['emails']) )
>                 return FALSE;
>         }
>         return TRUE;
>
> }
>
> Then using beforeSave to serialize the field and afterFind to
> unserialize the field.
>
> Thanks,
>
> Gary Dalton

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: validation of serialized data

2010-02-08 Thread euromark
no
thats usually never a good idea

you cant really edit them properly
or search by them, etc...

use the cakeish "hasMany" relations
if you bake your mvc, you will be amazed how easy and yet powerful
your forms gonna be in almost no time

and its very easily extendable - if you plan that some day


On 8 Feb., 21:12, bujanga  wrote:
> Just some thinking and a question or two, please tell me if I am
> totally off base.
>
> I would like to store multiple email addresses and phone numbers per
> user. Using a serialized field might work for this. Is that a good
> usage?
>
> Next, how does one validate the data and properly save and find the
> data. Here is what I am thinking (not tested).
>
> Validate the Model using a custom validation function:
>
> var $validate = array(
>         'emails'        => array(
>                 'is_email'      => array(
>                         'rule' => array('g_isEmail'),
>                         'required'              => TRUE,
>                         'allowEmpty'    => FALSE,
>                         'message' => 'You must enter at least 1 valid email 
> address'
>                 ),
>         ),
> )
>
> function g_isEmail($check){
>         if ( !isset($this->data['Model']['emails']) ){
>                 return FALSE;
>         }
>         if ( is_array($this->data['Model']['emails']) ){
>                 foreach( $this->data['Model']['emails'] as $email ){
>                         if ( !Validate::email($email) )
>                                 return FALSE;
>                         }
>                 }
>         }elseif( !Validate::email($this->data['Model']['emails']) )
>                 return FALSE;
>         }
>         return TRUE;
>
> }
>
> Then using beforeSave to serialize the field and afterFind to
> unserialize the field.
>
> Thanks,
>
> Gary Dalton

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


validation of serialized data

2010-02-08 Thread bujanga
Just some thinking and a question or two, please tell me if I am
totally off base.

I would like to store multiple email addresses and phone numbers per
user. Using a serialized field might work for this. Is that a good
usage?

Next, how does one validate the data and properly save and find the
data. Here is what I am thinking (not tested).

Validate the Model using a custom validation function:

var $validate = array(
'emails'=> array(
'is_email'  => array(
'rule' => array('g_isEmail'),
'required'  => TRUE,
'allowEmpty'=> FALSE,
'message' => 'You must enter at least 1 valid email 
address'
),
),
)

function g_isEmail($check){
if ( !isset($this->data['Model']['emails']) ){
return FALSE;
}
if ( is_array($this->data['Model']['emails']) ){
foreach( $this->data['Model']['emails'] as $email ){
if ( !Validate::email($email) )
return FALSE;
}
}
}elseif( !Validate::email($this->data['Model']['emails']) )
return FALSE;
}
return TRUE;
}

Then using beforeSave to serialize the field and afterFind to
unserialize the field.

Thanks,

Gary Dalton

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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