<p>I found this on the web:</p>

<pre><code> public function rules(){
    return array(
        array('customer_name,customer_email', 'default', 'setOnEmpty' =&gt; true, 'value' =&gt; null),
    );
}
</code></pre>

<p><a href="https://stackoverflow.com/questions/14850081/how-can-i-set-a-date-to-null-in-yii">https://stackoverflow.com/questions/14850081/how-can-i-set-a-date-to-null-in-yii</a></p>

<p>has fixed my issue.</p>

<p>thanks!</p>

CC BY-SA 3.0
2015-02-19T12:52:47.210Z
2015-02-19T12:52:47.210Z
2017-05-23T12:38:53.957Z
Gary Constable
<p>I have a question on Craft's Active Record,</p>

<pre><code> protected function defineAttributes(){
        'customer_ref' =&gt; array(
            AttributeType::String,
            'required' =&gt; true
        ), 
        'fault_code' =&gt; array(
            AttributeType::String,
            'required' =&gt; true
        ),
        'supplier_agent' =&gt; array(
            AttributeType::String,
            'required' =&gt; true
        ), 
        'response_delay' =&gt; array(
            AttributeType::String,
            'required' =&gt; true
        ) 
}
</code></pre>

<p>I have my defined attributes method, when I set <code>required = true</code>, and the field is empty the record fails to save!</p>

<p>When I set it as required = false (or just not add the required part) , the record will save but none of the field values get inserted to the database, I have a blank row.</p>

<p>So what do i do, I just want it to insert the row, if there is something missing let it be missing!</p>

<p>Any ideas?</p>

<p>Thanks,</p>

<records>
The Active Record
# The Active Record

(Asked by: username_0 on 2015-02-19)

I have a question on Craft's Active Record,
 protected function defineAttributes(){
        'customer_ref' => array(
            AttributeType::String,
            'required' => true
        ), 
        'fault_code' => array(
            AttributeType::String,
            'required' => true
        ),
        'supplier_agent' => array(
            AttributeType::String,
            'required' => true
        ), 
        'response_delay' => array(
            AttributeType::String,
            'required' => true
        ) 
}

I have my defined attributes method, when I set required = true, and the field is empty the record fails to save!
When I set it as required = false (or just not add the required part) , the record will save but none of the field values get inserted to the database, I have a blank row.
So what do i do, I just want it to insert the row, if there is something missing let it be missing!
Any ideas?
Thanks,

**Tags:** records

---

## 1 answers

### Answer by username_0 on 2015-02-19. Score: 1

I found this on the web:
 public function rules(){
    return array(
        array('customer_name,customer_email', 'default', 'setOnEmpty' => true, 'value' => null),
    );
}

https://stackoverflow.com/questions/14850081/how-can-i-set-a-date-to-null-in-yii
has fixed my issue.
thanks!


---

