I'm using Isomorphic SmartClient/SmartGWT Framework (v9.0p_2013-09-17/Pro Deployment 2013-09-17) and using serverside datasources...
my ds.xml looks like this:
when I use this code to add a new entry, it fails
with "Field 'app_id' doesn't have a default value"
but if I do two separate lookups/DB calls to get the actual DB ids of username (userId) and appname (appId), and use those ids in the call instead, it works:
Is there some trick to getting add to work with the foreign fields? or does this not work like I assumed it would?
Thanks,
Brian
my ds.xml looks like this:
Code:
<DataSource ID="app_users" serverType="sql" dataSourceVersion="1" autoDeriveSchema="true"> <fields> <field name="id" type="sequence" primaryKey="true"> <columnCode>b80bb7740288fda1f201890375a60c8f</columnCode> </field> <field name="app_id" foreignKey="apps.id"/> <field name="user_id" foreignKey="users.id"/> <field name="create_date" type="datetime"> <columnCode>3d8252a0fb3ab8a64613f6f814ed08ca</columnCode> </field> <field name="enabled" type="integer"> <columnCode>a10311459433adf322f2590a4987c423</columnCode> </field> <field name="is_admin" type="integer"> <columnCode>c60879c6b41321704ee88fbc7b9a73e4</columnCode> </field> <field name="app_name" includeFrom="apps.name"/> <field name="app_enabled" includeFrom="apps.enabled"/> <field name="user_name" includeFrom="users.name"/> <field name="user_enabled" includeFrom="users.enabled"/> </fields> <allowAdvancedCriteria>false</allowAdvancedCriteria> <tableCode>43738f9fce49550bbb66a533c637b647</tableCode> <generatedBy>v9.0p_2013-09-17/Pro Deployment 2013-09-17</generatedBy> </DataSource>
Code:
DataSource ds = DataSourceManager.get(getDataSource()); Map<String,Object> record = new HashMap<String,Object>(); record.put("user_name", name); record.put("app_name", appName); record.put("create_date", new Date()); ds.add(record);
but if I do two separate lookups/DB calls to get the actual DB ids of username (userId) and appname (appId), and use those ids in the call instead, it works:
Code:
//for some reason, when doing an add, you have to have the DB ids long appId = getAppId(appName); long userId = getId(DS_USERS, name); DataSource ds = DataSourceManager.get(getDataSource()); Map<String,Object> record = new HashMap<String,Object>(); record.put("user_id", userId); record.put("app_id", appId); record.put("create_date", new Date()); ds.add(record);
Thanks,
Brian