1

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,

1 Answer 1

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.