⚠ 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

howto set relation_n_n



aps

aps
  • profile picture
  • Member

Posted 01 October 2013 - 09:17 AM

Hi guys,

 

I am newbie with GC. I have a problem with relation_n_n. I have 3 tables:

user

-username (PK)

-password

-fullname

 

role

-level (PK)

-description

 

user_role

-username (FK)

-level (FK)

 

My GC function:

$crud->set_table('user');

$crud->set_relation_n_n('User Role','user_role','role','username','level','description');

 

When I click Save Button, successfully saved. But my data is not saved in database.

How to fix it? Thank for your help guys

 

 


davidoster

davidoster
  • profile picture
  • Member

Posted 01 October 2013 - 16:39 PM

Hello and welcome to the forums [member=aps].

Make sure you use the set_primary_key function to set the primary keys.


aps

aps
  • profile picture
  • Member

Posted 03 October 2013 - 02:58 AM

I try to change data type of username from varchar to int and it works for me. I think relation_n_n is only support int, not varchar. Am I right?

 

Thank for your help davidoster.

I will try your suggestion.


davidoster

davidoster
  • profile picture
  • Member

Posted 11 October 2013 - 04:03 AM

It is not because of the set_relation_n_n it is because of the primary key. Usually the library looks for the primary_key with the name of id. If the name of the primary_key is different we tend to set it via set_primary_key so we don't have any problems.