⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

set_relation with table prefix



kanted
  • profile picture
  • Member

Posted 15 November 2015 - 11:56 AM

Table1 has  id, firstname, lastname

Table2 has A|id, address,city. A|id is the primary key. how do i set relationship. since id column  has a prefix of "A|" 

 


Paul Savostin
  • profile picture
  • Member

Posted 15 November 2015 - 12:51 PM

http://www.grocerycrud.com/documentation/options_functions/set_primary_key


kanted
  • profile picture
  • Member

Posted 15 November 2015 - 13:38 PM

Great Thanks Paul. But except  A|id no other column is primary key & how would i relate it with other table. only difference in table is it has a prefix 

 

table1: primary_key , vs a table2 prefix_primary_key no other column has primary key which can be related.

 

example 

 

employee
id name

1 steve
2 rob
3 bell

position
position_id  e_id       position

a                 e_1        manager
b                 e_2        seller
c                 e_3        director

 

result

name position

steve manager
rob seller
bell director


Paul Savostin
  • profile picture
  • Member

Posted 16 November 2015 - 01:12 AM

I dont understand actualy what u need in this question :(

u mean that value in table 'position' column e_id have format like e_1, e_2, e_3 or what?

if so then u should change it cause this is horribly wrong!

 

why u dont do like this one ???

employee table
id name

1 steve
2 rob
3 bell

 

position table
id  employe
r_id       position
1        1                   manager
2        2                   seller
3         3                 director


kanted
  • profile picture
  • Member

Posted 16 November 2015 - 08:05 AM

Thanks for your reply. I know that it in the regular table format as you suggested it works

 

 if we remove the prefix then it will not be the primary key. see the below table i have added more sample data. can we use concatenate option during table relation ?

 

position
position_id  e_id       position

a                 e_1        manager
b                 e_2        seller
c                 e_3        director

e                 x_1        zonemanager

f                  x_2        zoneseller


Paul Savostin
  • profile picture
  • Member

Posted 16 November 2015 - 11:52 AM

I told u,  change u database schema. U have ID in one table 1, 2, 3 and in another e_1, x_2, ???_3, ???_4.  So how u want to join that fields?