0

我正在使用 Yii php,但我遇到了数据库中重复条目的问题。

为了演示,假设我有这个:

id(pk) | parent_id | parent_name| is_male(boolean) | is_female(boolean)
------------------------------------------------------------------------
1      |     1     |parent1     | true             | false                
------------------------------------------------------------------------
2      |     1     |parent1     | false            | true
------------------------------------------------------------------------
3      |     2     |parent2     | false            | true
------------------------------------------------------------------------

从技术上讲,parent1 是相同的,但同时用作女性和男性。以上是正确但效率低下,重复是不必要的,因为它们只属于同一个父母。如何删除重复的 parent1并将第一行is_female更新为true

例如导致:

id(pk) | parent_id | parent_name| is_male(boolean) | is_female(boolean)
------------------------------------------------------------------------
1      |     1     |parent1     | true             | true                
------------------------------------------------------------------------
3      |     2     |parent2     | false            | true
------------------------------------------------------------------------

我如何在 Yii php 中以编程方式执行此操作?谢谢!

4

1 回答 1

0
    in update mode loadModel query change means you no need to delete the duplicated , the first record will be get updated 

  Controller file
 ----------------    
          Function loadModel($id)
           {
    $where='id='.$id .' Group by parent_id '
    $model=Model()->find($where);
           }

    in view file 
    ------------
            <?php
            if($model->parent_id==1)  // when the parent_id is 1 the female field will visible , sure not  affect the created 
            {
             echo $form->textField($model, 'is_female'); ?>
            }

        ?>
于 2013-10-07T07:13:46.060 回答