why not separate it to 2 model and set hasMany relationship. it will
be more easier.

On Aug 5, 3:19 pm, hoss7 <hoss...@gmail.com> wrote:
> i have this array:
>
> Array
> (
>     [Usercat] => Array
>         (
>             [subcat_id] => Array
>                 (
>                     [0] => 3
>                     [1] => 1
>                 )
>
>             [user_id] => 2
>             [group_id] => 5
>         )
>
> )
>
> i want befor save data in usercat table, search usercat table for
> duplicate subcat_id with user_id if subcat_id with user_id not exist
> store subcat_id with user_id,what i am must to do?
>
> example:
> i have subcat_id=1 with user_id=2 in usercat table,now i want only
> save subcat_id=3 with user_id=2 in usercat table.
>
> this is my function for save array subcat_id in usercat table in
> Usercat Model:
>
> function save($data = null, $validate = true, $fieldList =  array())
> {
>                 $return = false;
>                 if (isset($data['Usercat']['subcat_id']) &&
> is_array($data['Usercat'] ['subcat_id'])) {
>                         foreach ($data['Usercat']['subcat_id'] as
> $subcat) {
>                                 $saveData = array(
>                                         'user_id' => $data['Usercat']
> ['user_id'],
>                                         'subcat_id' => $subcat,
>                                 );
>                                 $this->create();
>                                 $return = parent::save($saveData); //
> here can add some tests ...
>                         }
>                 }elseif (isset($data['Usercat']['subcat_id']) && !
> is_array($data['Usercat'] ['subcat_id'])){
>
>                                  $this->create();
>                                  $return = parent::save($data);
>                                 }
>                 return $return;
>         }

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

Reply via email to