⚠ 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

non auto-increment primary key, nullable foreign key



goFrendiAsgard
  • profile picture
  • Member

Posted 11 November 2011 - 02:09 AM

Dear, web-johnny

First of all I want to thank you for your great job. It helps me to save a lot of time.
I've several questions related to groceryCRUD.

1. I try to use a primary key which is not in INT data type. I use user_name as a primary key of table_user. I've successfully add a user, but when I click "edit" (a link that appear after I insert new data), It showed error. I guess it is related to "auto increment" (Maybe you assume that all primary key should be integer and auto increment). It is not a big problem since I can change my table structure so that each table will have "auto increment primary key". The question is: Is it right that current groceryCRUD version only support "auto increment primary key"?

2. I also try to make a navigation table which is used as "tree structure" representation.
table_navigation(id, parent_id, is_root, title, url)

"parent_id" is a foreign key to "id", and it is allowed to be null.
I use before_insert and before_update callback, both are directed to before_insert_or_update_navigation function.

public function before_insert_or_update_navigation($post_array){
if($post_array['is_root']==1){
unset($post_array['parent_id']); //this doesn't work, there is no change for the value of parent_id
$post_array['parent_id'] = NULL; //doesn't work as above
$post_array['parent_id'] = ''; //doesn't work, produce error
}
return $post_array;
}

Is that any way to do what I want correctly?


thank you in advance
goFrendiAsgard;

goFrendiAsgard
  • profile picture
  • Member

Posted 12 November 2011 - 01:47 AM

7 views and 0 comments :D
May be there are a lot of you interested in this topic, but cannot find the answer yet. For temporary answer:[list=1]
[*]I think the answer is yes, when look at database example, all primary key are auto increment (except middle tables). Nothing wrong, just carefully define your tables :D
[*]I still can't do that with groceryCRUD, but I think I can use mysql's trigger. I hope there is a solution by using groceryCRUD itself. Using trigger is painful, since I should debug a lot of code whenever an error appeared :D
[/list]