SmartGWT Pro:
Isomorphic SmartClient/SmartGWT Framework (v9.0p_2013-09-17/Pro Deployment 2013-09-17)
One thing to note - I am doing all of this on the server side using
import com.isomorphic.datasource.DataSource;
import com.isomorphic.datasource.DataSourceManager;
and this code is NOT used on the clientside.
I have a mySQL users table:
users table:
id|user_name
------------
1|jsmith
Here is the datasource XML for it:
and I have a few other tables that use the user_id as a foreign key. I want to be able to do things with the other tables based on the user_name vs the user_id (jsmith vs 1). An example test table:
test table:
id|user_id|text
1|1|testing
where user_id is a FK pointing to the id in the users table
This works just fine:
but what I would like to be able to do is something like
When I try this I get:
which makes it sounds liek i need soemthign more in my DS.XML file.
I do have a datasource setup for both the users and test tables and I have autoDeriveSchema="true" for both of them. In the test datasource, I have the user_id setup as:
I also tried adding to the test table definition:
<field includeFrom="users.user_name"/>
and that didn't work either.
I've searched for examples of using foreign keys in datasources and haven't been able to find any examples of its use like this so I'm not sure if I can't find it or we cannot use it like this. I suspect it can be done, I just haven't stumbled on how yet. if the answer is RTFM (or RTF forum), please point me to where it is - I'd be glad to read how to do this. I know I'm close but I just can't get the last bit. :)
I know I could just abandon this idea completely and just use the user_id everywhere (and that will work), but this seems like something I should be able to do and I'm curious how to do it.
Thanks,
Brian
Isomorphic SmartClient/SmartGWT Framework (v9.0p_2013-09-17/Pro Deployment 2013-09-17)
One thing to note - I am doing all of this on the server side using
import com.isomorphic.datasource.DataSource;
import com.isomorphic.datasource.DataSourceManager;
and this code is NOT used on the clientside.
I have a mySQL users table:
users table:
id|user_name
------------
1|jsmith
Here is the datasource XML for it:
Code:
<DataSource ID="users" serverType="sql" dataSourceVersion="1" autoDeriveSchema="true"> <fields> <field name="id" type="sequence" primaryKey="true"> <columnCode>b80bb7740288fda1f201890375a60c8f</columnCode> </field> <field name="user_name" type="text" length="45"> <columnCode>c56f5648d4c0e137f9de3dfc7a54d55b</columnCode> </field> </fields> <allowAdvancedCriteria>false</allowAdvancedCriteria> <tableCode>9bc65c2abec141778ffaa729489f3e87</tableCode> <generatedBy>v9.0p_2013-09-17/Pro Deployment 2013-09-17</generatedBy> </DataSource>
test table:
id|user_id|text
1|1|testing
where user_id is a FK pointing to the id in the users table
This works just fine:
Code:
DataSource ds = DataSourceManager.get("test"); Map<String,Object> record = new HashMap<String,Object>(); record.put("user_id", 1); record.put("text", "testing"); ds.add(record);
Code:
DataSource ds = DataSourceManager.get("test"); Map<String,Object> record = new HashMap<String,Object>(); record.put("users.user_name", "jsmith"); record.put("text", "testing"); ds.add(record);
Code:
"DataSource - DataSource auditlog includes fields from DataSource users but we cannot establish a direct or indirect relation between those DataSources. You must specify foreignKey field(s) on the including DataSource (test) that either express a direct relationship to users, or express an indrect relationship via one or more intervening tables"
I do have a datasource setup for both the users and test tables and I have autoDeriveSchema="true" for both of them. In the test datasource, I have the user_id setup as:
Code:
<field name="user_id" type="integer"> <columnCode>e8701ad48ba05a91604e480dd60899a3</columnCode> <fkColumnCode>b80bb7740288fda1f201890375a60c8f</fkColumnCode> <fkTableCode>9bc65c2abec141778ffaa729489f3e87</fkTableCode> </field>
<field includeFrom="users.user_name"/>
and that didn't work either.
I've searched for examples of using foreign keys in datasources and haven't been able to find any examples of its use like this so I'm not sure if I can't find it or we cannot use it like this. I suspect it can be done, I just haven't stumbled on how yet. if the answer is RTFM (or RTF forum), please point me to where it is - I'd be glad to read how to do this. I know I'm close but I just can't get the last bit. :)
I know I could just abandon this idea completely and just use the user_id everywhere (and that will work), but this seems like something I should be able to do and I'm curious how to do it.
Thanks,
Brian
Comment