Db constraints to relation

I made a test db with 3 tables

table_a ( table_a_ id as integer and primary key)
table_b ( table_b_ id as integer and primary key, table_a_ id db constraint to table_a id)
table_c ( table_c
id as integer and primary key, table_a_ id db constraint to table_a_id)

in the relation form of servoy when i ask to create all my relations, it create the following relations:
table_a
=> fk_table_b_table_a
=> fk_table_c_table_a
table_b
=> pk_table_a

and nothing for table_c

If i look in the servoy log, it said that it can’t create other pk_table_a relation because it already exist (for table b)

How can i recreate all my relation in servoy ( 300 constraints well defined in db engine)

Can you change the relation naming rule for example pk_table_b_table_b_fields_table_a ?

Thanks

Hi Fabrice,

erdione:
How can i recreate all my relation in servoy ( 300 constraints well defined in db engine)

Yes you can (re)create all foreign-key constraints being used in the database in Servoy. Just open the Relations window. Select the correct connection name at the top and hit the Create button. After it is done you have all 300 foreign-key constraints in Servoy as well. keep in mind these constraints will be un-editable in Servoy.

erdione:
Can you change the relation naming rule for example pk_table_b_table_b_fields_table_a ?

You can’t change the naming rule but you can change the name after you selected all the properties though (except from the automatically created relations like discussed above)

Hope this helps.

Thanks for your reply,

But all that you explain is what i’ve done in servoy (automatically create relation from the good connection pointing to db with constraints etc…) and the result is that there are missing relations because of duplicated name… (for exemple in table_c)

For example if users table id is in many table because i want to know who created the record only one table (surely the first one) will get the relation

Fabrice,

You are correct, the current mechanism to generate relations from database foreign keys does not support a table with multiple FK relations referring to it.

We will change that in next versions of Servoy 3.1 and 3.5.

The new relation names will be :
table_a (unchanged)
=> fk_table_b_table_a
=> fk_table_c_table_a
table_b
=> table_b_to_table_a
table_c
=> table_c_to_table_a

Rob

Thanks for your reply

I think that The new relation should better be named like that
fk_field_fktable_pktable because we can have more than one constraint from one table to another table:
for exemple see db diagram below and result of a sql query to discover constraint

table_user
=> fk_modifuserid_table_b_table_user
=> fk_creatuserid_table_b_table_user
=> fk_table_c_table_user
table_b
=> pk_modif_user_id_table_b_table_user
=> pk_create_user_id_table_b_table_user
table_c
=> pk_tab_user_id_table_c_table_user

“exec sp_fkeys @pktable_qualifier = null, @pktable_owner = null, @pktable_name = ‘table_user’”

table_user tab_user_id testfk dbo table_b create_user_id FK_create_user_id_table_b_table_a PK_table_a
table_user tab_user_id testfk dbo table_b modif_user_id FK_modif_user_id_table_b_table_a PK_table_a
table_user tab_user_id testfk dbo table_c tab_user_id FK_tab_user_id_table_c_table_user PK_table_a

Does anybody have any date for the 3.5.1 Release ?

I need it to create my 2 or 3 hundreds relations in servoy (constraints are already created in my MSSQL server), it could be stupid to recreate it in Servoy

Thanks