php - Does RedBean need a "id" primary key? -
if use redbean orm, need add primary key named "id" every table in database?
in db have few tables have primary keys pairs of 2 or 3 fields, or primary keys other names "id" (yes, change name "id", wouldn't reflect reality, because not ids)
example:
table1 - stores posts:
id integer primary key autoincrement, name text, title text, content text,
table2 - stores meta posts:
post integer default 0, # <- references "id" "posts" name text, value text, primary key(name, post), constraint posts_meta foreign key(post) references posts(id) on delete cascade on update restrict
would redbean work kind of db structure?
unfortunately, how current table structure is, couldn't use redbean. every table needs have auto-increment primary key. slight downfall, makes integration existing product more difficult.
a couple of threads failed use redbean due constraint, responses author, gabor de mooij:
http://groups.google.com/group/redbeanorm/browse_thread/thread/6d5582275326744f?pli=1
http://groups.google.com/group/redbeanorm/browse_thread/thread/4fa7b29b453dcdb8
redbean not require primary key field named "id", however. can format name of primary key column liking using formatbeanid()
method, seen in example below, prefixes table name "id" conditionally. eg) table users
have primary key users_id
. using formatting, can detailed id name needed.
http://redbeanphp.com/community/wiki/index.php/prefixes
hopefully restraint lifted in future, since hamper integration existing products.
edit: alternative orm, i've heard of doctrine: http://www.doctrine-project.org/. haven't used it, seems standard many working php.
edit 2: , credit jason bringing attention new method integrating redbean existing project database might not set it. wanted update answer in case people still reference problem. gabor suggested making views map tables, can set view have proper structure required redbean. have not tested this, has gotten positive feedback users. adds overhead , maintenance when altering tables, seems best , complete answer issue date. http://www.redbeanphp.com/faq#beanformatter
Comments
Post a Comment