'required' key serves not existent fields, false by default.
var $validate = array(
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
'required' => true // this rule will
fail if data array do not have "name" key
),
),
);
On Sep 30, 7:52 pm, psybear83 <[email protected]> wrote:
> Hi everybody
>
> I have baked the following very straight-forward model:
>
> class Post extends AppModel {
> var $name = 'Post';
> var $displayField = 'name';
> var $validate = array(
> 'name' => array(
> 'notempty' => array(
> 'rule' => array('notempty')
> ),
> ),
> );
>
> }
>
> It only needs a value for "name" to be saved.
>
> Now I've written the following 3 tests:
>
> function testShouldNotBeValidWithEmptyName() {
> $this->Post->create(array('name' => ''));
> $this->assertFalse($this->Post->validates());
> }
>
> function testShouldNotBeValidWithoutName() {
> $this->Post->create();
> $this->assertFalse($this->Post->validates()); // Fails!
> }
>
> function testShouldNotBeValidWithNullName() {
> $this->Post->create(array('name' => null));
> $this->assertFalse($this->Post->validates());
> }
>
> I expect all three of them to work, but the 2nd one fails! So why does
> it validate when there truly is no value for the "name" field? Is this
> really the way it should be, or is it a bug?
>
> I'm on version 1.3.4.
>
> Thanks for help
> Josh
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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en