Skip to main content
Renand
Participant
March 23, 2010
Answered

Update an ORM record, but with empty value

  • March 23, 2010
  • 2 replies
  • 796 views

Hi All, Excuse my poor english and my poor coldfusion level

I have some problems to update datas with ORM objects.

1) I have a customer objet with a job property (many-to-one relations)
2) I have a job object ( a list of job )

When I update a customer with customerOBJ.setjob( jobOBJ ); it's OK

But when I don't arrive to restore empty value for job.

When I try this :

customerOBJ.setJob(), I have an error because the parameters is not a job type

Do you have some informations about that ?

Thanks in advance.

    This topic has been closed for replies.
    Correct answer Owainnorth

    Hi matey

    Use this to get a null value: javacast("null",'"")

    Therefore to clear the value:

    customerOBJ.setJob( javacast("null","") ) ;

    That should do you nicely. If you use it in a few places, you can create yourself a function:

    <cffunction name="null" access="public" returntype="any">

      <cfreturn javacast("null","") />

    </cffunction>

    Then use that:

    customerOBJ.setJob( null() ) ;

    2 replies

    Owainnorth
    OwainnorthCorrect answer
    Inspiring
    March 23, 2010

    Hi matey

    Use this to get a null value: javacast("null",'"")

    Therefore to clear the value:

    customerOBJ.setJob( javacast("null","") ) ;

    That should do you nicely. If you use it in a few places, you can create yourself a function:

    <cffunction name="null" access="public" returntype="any">

      <cfreturn javacast("null","") />

    </cffunction>

    Then use that:

    customerOBJ.setJob( null() ) ;

    Fernis
    Inspiring
    March 23, 2010

    Have you tried customerOBJ.setJob("") ?

    -Fernis

    Renand
    RenandAuthor
    Participant
    March 23, 2010

    Hi Fernis,

    Yes I try this case.

    Normaly the paramters must be an object. but I dont know how restore the default value 'empty string' (Null)

    Fernis
    Inspiring
    March 23, 2010

    Do you use bi-directional relations?

    Have you set the relation with ORM generated implicit add<propertyname> methods?

    If so, you should remove the relation before you set the value to empty on the joined table, with the remove<propertyname> implicit method.

    I'm way tired right now, so I'm sorry if that's a bit hit-and-miss guessing...

    -Fernis