Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Update an ORM record, but with empty value

New Here ,
Mar 23, 2010 Mar 23, 2010

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.

685
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Mar 23, 2010 Mar 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() ) ;

Translate
Enthusiast ,
Mar 23, 2010 Mar 23, 2010

Have you tried customerOBJ.setJob("") ?

-Fernis

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2010 Mar 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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 23, 2010 Mar 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2010 Mar 23, 2010
LATEST

So,

the relation is not bi-directionnal (I think ).

And Yes,I use the implicit add method for this property.

the setting is :

<cfproperty name="job" fkcolumn="job_id"  fieldtype="many-to-one" cfc="job" type="job" required="no" hint="Le métier du client"  />

When I add a Job I use fox ex:

<cfscript>

     customerOBJ = entityLoad( "customer", 1, true );

     jobOBJ = entityLoad( "job", 1, true );

     customerOBJ.setJob( jobOBJ );

</cfscript>

When I try to use

customerOBJ.removeJob();

I have this error :

The  method removeJob was not found in component

and @Owainnorth

Yes !

It's ok with customerOBJ.setJob( javacast("null","") ) ;

Thank you to you two

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 23, 2010 Mar 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() ) ;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources