Copy link to clipboard
Copied
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.
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() ) ;
Copy link to clipboard
Copied
Have you tried customerOBJ.setJob("") ?
-Fernis
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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 :
and @Owainnorth
Yes !
It's ok with customerOBJ.setJob( javacast("null","") ) ;
Thank you to you two
Copy link to clipboard
Copied
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() ) ;