beforeInsert not called on save()? (1.0-RC1)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

beforeInsert not called on save()? (1.0-RC1)

Steven Devijver
Hey,

I have this domain class:

class Report {
        Date createdAt
        String environment
        String reportName
       
        static constraints = {
                environment(blank: false, nullable: false)
                reportName(blank: false, nullable: false)
        }
       
        def beforeInsert = {
                createdAt = new Date()
        }
}

When I create a new object and call the save() method I get a
validation error for the createdAt field.

Does this mean beforeInsert is not called when saving a new object?

Thanks

Steven

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: beforeInsert not called on save()? (1.0-RC1)

Graeme-Rocher
validation is executed before save is called on the session, so it
never gets that far

Cheers

On 10/29/07, Steven Devijver <[hidden email]> wrote:

> Hey,
>
> I have this domain class:
>
> class Report {
>         Date createdAt
>         String environment
>         String reportName
>
>         static constraints = {
>                 environment(blank: false, nullable: false)
>                 reportName(blank: false, nullable: false)
>         }
>
>         def beforeInsert = {
>                 createdAt = new Date()
>         }
> }
>
> When I create a new object and call the save() method I get a
> validation error for the createdAt field.
>
> Does this mean beforeInsert is not called when saving a new object?
>
> Thanks
>
> Steven
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: beforeInsert not called on save()? (1.0-RC1)

Steven Devijver
Hey Graeme,

The two other fields are properly filled in, I don't get validation
errors for them.

Do you mean that the validation step also checks the createdAt field?

Thanks

Steven



On 10/29/07, Graeme Rocher <[hidden email]> wrote:

> validation is executed before save is called on the session, so it
> never gets that far
>
> Cheers
>
> On 10/29/07, Steven Devijver <[hidden email]> wrote:
> > Hey,
> >
> > I have this domain class:
> >
> > class Report {
> >         Date createdAt
> >         String environment
> >         String reportName
> >
> >         static constraints = {
> >                 environment(blank: false, nullable: false)
> >                 reportName(blank: false, nullable: false)
> >         }
> >
> >         def beforeInsert = {
> >                 createdAt = new Date()
> >         }
> > }
> >
> > When I create a new object and call the save() method I get a
> > validation error for the createdAt field.
> >
> > Does this mean beforeInsert is not called when saving a new object?
> >
> > Thanks
> >
> > Steven
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>
> --
> Graeme Rocher
> Grails Project Lead
> http://grails.org
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: beforeInsert not called on save()? (1.0-RC1)

Graeme-Rocher
On 10/29/07, Steven Devijver <[hidden email]> wrote:
> Hey Graeme,
>
> The two other fields are properly filled in, I don't get validation
> errors for them.
>
> Do you mean that the validation step also checks the createdAt field?

Yes, all fields are required by default

Cheers

>
> Thanks
>
> Steven
>
>
>
> On 10/29/07, Graeme Rocher <[hidden email]> wrote:
> > validation is executed before save is called on the session, so it
> > never gets that far
> >
> > Cheers
> >
> > On 10/29/07, Steven Devijver <[hidden email]> wrote:
> > > Hey,
> > >
> > > I have this domain class:
> > >
> > > class Report {
> > >         Date createdAt
> > >         String environment
> > >         String reportName
> > >
> > >         static constraints = {
> > >                 environment(blank: false, nullable: false)
> > >                 reportName(blank: false, nullable: false)
> > >         }
> > >
> > >         def beforeInsert = {
> > >                 createdAt = new Date()
> > >         }
> > > }
> > >
> > > When I create a new object and call the save() method I get a
> > > validation error for the createdAt field.
> > >
> > > Does this mean beforeInsert is not called when saving a new object?
> > >
> > > Thanks
> > >
> > > Steven
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe from this list please visit:
> > >
> > >     http://xircles.codehaus.org/manage_email
> > >
> > >
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email