Skip to main content
Renand
Participant
Mar 23, 2010 2:30 PM UTC
Answered

Update an ORM record, but with empty value

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 is closed to new replies. Start a new post to keep the conversation going.
    Owainnorth
    OwainnorthCorrect answer
    Inspiring
    Mar 23, 2010 4:17 PM UTC

    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() ) ;

    5 replies

    Owainnorth
    OwainnorthCorrect answer
    Inspiring
    Mar 23, 2010 4:17 PM UTC

    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() ) ;

    Translate
    Fernis
    Inspiring
    Mar 23, 2010 3:39 PM UTC

    Have you tried customerOBJ.setJob("") ?

    -Fernis

    Translate
    Renand
    RenandAuthor
    Participant
    Mar 23, 2010 3:43 PM UTC

    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)

    Translate
    Fernis
    Inspiring
    Mar 23, 2010 4:12 PM UTC

    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

    Translate