How to ask CF9 ORM (hibernate) to use CHAR(2) as sql column type?
component persistent=true {
property name="id" fieldtype="id" ormtype="integer" generated="always" generator="identity";
property name="char2Prop" fieldtype="column" sqltype="char(2)";
}
Related
The docs show an example where you start listening to new data with the component, but how would you do an initial query before listening for new data?
If your initial query differs from subscription you should probably use <Query /> component and use subscribeToMore function for subscription.
Docs: https://www.apollographql.com/docs/react/advanced/subscriptions.html#subscribe-to-more
I have a datasource called "cforms" which has access to two database
"cforms" and "cquizes"
I wish to create the following query:
select * from cquizes.tb_depts;
I have a model for table "tb_depts":
<cfcomponent extends="Model">
<cffunction name="init">
<cfset table("tb_depts")>
</cffunction>
</cfcomponent>
And my controller:
list = model("tb_depts").findAll(order="id");
When I run this controller/action. It gives me the following error:
[Macromedia][Oracle JDBC Driver][Oracle]ORA-00942: table or view does not exist
And it generates the following query:
SELECT * FROM tb_depts
I understand what the problem is because since "tb_depts" doesn't exist in database "cforms" it throws that not found error. However is there are way to tell the model that using the datasource "cforms" access database "cquizes". For example
cquizes.tb_depts
Its seems to use the database that matches the datasource name. Is there a way to work around this functionality.
If you need to get data from another database, There is an alternative way. For that you need to create a datasource for your second database cquizes. Then use that datasource name in the model file. This will override default datasource for that model.
For example, If you name your second datasource as cquizdatasource then in your model would be like
<cfcomponent extends="Model">
<cffunction name="init">
<cfset dataSource("cquizdatasource")>
<cfset table("tb_depts")>
</cffunction>
</cfcomponent>
Your query should work fine with the said scenario in the question. There are limitations to this, check out the link to know more.
In ColdFusion using ORM, how do I to map a foreign key column referring two tables?
My example.
At the moment an Image can belong to either a human or alien
Image.cfc
property name="imageID" fieldtype="id" generator="guid";
// Related Object Properties (many-to-one)
property name="Human" fieldtype="many-to-one" fkcolumn="HumanID" cfc="human";
property name="Alien" fieldtype="many-to-one" fkcolumn="AlienID" cfc="alien";
This leaves me with a table looking like this..
Image.cfc
ID NAME HumanID AlienID
1 img1 10 NULL
2 img2 NUll 8
To me NULLs smells bad!
So can I replace this with one mapping for both objects? Or If I create a category table? Any Ideas?
Thanks
Spark
You can't map a single property to more than one parent object. So you have two options here.
You will need to map this as a class per heirarchy where you will have classes for HumanImage and AlienImage that extend the base Image class
// Image.cfc
component persistent="true" {
property name="id" generator="guid";
property name="name";
}
// AlienImage.cfc & HumanImage.cfc
component persistent="true" extends="Image" joincolumn="id" {
}
// Alien.cfc
component persistent="true" {
property name="id" generator="guid";
property name="Image" fieldtype="one-to-many" cfc="AlienImage"
fkcolumn="fkAlienID";
}
// Human.cfc
component persistent="true" {
property name="id" generator="guid";
property name="Image" fieldtype="one-to-many" cfc="HumanImage"
fkcolumn="fkHumanID";
}
When attempting to do an EntitySave("publications",arguments); .. I receive the following error.
ids for this class must be manually assigned before calling save(): publications
I can't work out why.. My database primary keys are set up correctly, and I have setter=false these properties in my CFC. I have found a bit on this error doing a Google search, but nothing seems to indicate what is causing my issue here.
Here are my CFC's. Any pointers on what I might be doing wrong are appreciated. Thanks heaps in advance!
Publications.cfc
component persistent="true" table="publications"
hint="Publications"{
property name="id" fieldtype="id" setter="false";
property name="typeid" omrtype="int";
property name="name" ormtype="string";
property name="dateScheduled" ormtype="date" ;
property name="tstamp" ormtype="date";
property name="Article" fieldtype="one-to-many" cfc="publicationArticles" fkcolumn="publicationid";
}
publicationArticles.cfc
component persistent="true" table="publicationArticles"
hint="Publications"{
property name="id" fieldtype="id" setter="false" ;
property name="typeid" ormtype="int";
property name="title" ormtype="string" ;
property name="status" ormtype="boolean";
property name="publication" fieldtype="many-to-one" cfc="publications" fkcolumn="publicationid" ;
}
publicationTypes.cfc
component persistent="true" table="publicationTypes"
hint="Publicatin Type - Lookup"{
property name="id" fieldtype="id" setter="false" ;
property name="description" ormtype="string";
property name="publications" fieldtype="one-to-many" cfc="publications" fkcolumn="typeid" ;
}
You need a generator on the property.
property name="id" fieldtype="id" generator="identity";
Why does this not work in ColdFusion with ORM? I don't get any error but getval2() is blank
property name="ID" type="string" fieldtype="id" generator="guid";
property name="val1" type="string" ormtype="string" persistent=true;
property name="val2" type="any" persistent=false default="";
public statsEntity function init(){
variables.val2= this.getval1();
return Super.init();
}
what I think should happen is getval2() should be the value of val1.
Any ideas why this is not the case?
ORMExecuteQuery("from myTable")
Not sure I understand correctly, but init() only runs on new enitity so will NOT work here try postLoad() not init().