Adding relationship for table with 2 part key

Posts   
 
    
Jamanga
User
Posts: 93
Joined: 21-Jul-2006
# Posted on: 05-Jun-2009 08:17:02   

Hi,

I know I must be missing something.. I've inherited a dodgy database in that it has ZERO FK relationship information between the tables and fantastically inconsistent tables names. But thats my problem. I am trying to establish the relationships between the important tables e.g.

Table: TopProducts (2 part key: SKU, CATEGORY_ID) Table: Product (key: SKU) Table: Category (key: CATEGORY_ID)

I want to establish the relationship between TopProducts table and both Product and Category tables, but within the designer, when setting this up I seem to be only be table to select "Foreign Key Fields" from the one table?

I'm using version 2.6 of the designer, any ideas?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 05-Jun-2009 08:51:45   

I didn't catch your problem, but for the following:

Table: TopProducts (2 part key: SKU, CATEGORY_ID) Table: Product (key: SKU) Table: Category (key: CATEGORY_ID)

You should make sure that: 1- for the Prodcut entity SKU is set as the PK. 2- for the Category entity the CategoryId is set as the PK. 3- In the TopProducts SKU has the same dataType of the Product.SKU field. 4- Again the TopProducts.Categoryid has the same dataType as of the Category.CategoryId 5- You can define one custom relation having the topProdcuts in the Foreign Key side and Poduct in the Primary Key side. 6- Similarly you can define another custom relation having the topProdcuts in the Foreign Key side and Category in the Primary Key side.

Jamanga
User
Posts: 93
Joined: 21-Jul-2006
# Posted on: 09-Jun-2009 00:35:39   

Hi Walaa

Thanks for the quick response, I was trying to map the 2-part key table within the designer back to the 2 relevant tables, which I couldn't acheive, but working back the other way from single PK tables to the FK fields worked fine.

I do have one other request and I'm guessing it should be coded within the entity itself? Basically there is a field called Sku varchar[8] which maps to another field varchar[16], however the only difference is the varchar(16) has 8 trailing zeroes e.g. 12345678 vs 1234567800000000

Can a relationship be defined in this way i.e. with a calculated field, or do the values have to be an exact match?

Thanks!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Jun-2009 04:29:19   

Not at Designer. The best aproach (I think) is DynamicRelation (to use at code).

David Elizondo | LLBLGen Support Team