CodeIgniter Forums
dbforge add_key - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: dbforge add_key (/showthread.php?tid=5793)



dbforge add_key - El Forum - 02-04-2008

[eluser]Eric Barnes[/eluser]
I am trying to use the new dbforge to create a database. One issue that I can't seem to figure out is how to use the add_key to create a key on multiple fields.

Through straight mysql I am creating a table like this:
Code:
$sSQL = "CREATE TABLE `".$prefix."article2cat` (
`rel_id` bigint(20) NOT NULL auto_increment,
`article_id` bigint(20) NOT NULL default '0',
`category_id` bigint(20) NOT NULL default '0',
PRIMARY KEY  (`rel_id`),
KEY `article_id` (`article_id`,`category_id`)
);

Through dbforge I have this:
Code:
$this->dbforge->add_field($fields);
$this->dbforge->add_key('rel_id', TRUE);
$this->dbforge->add_key('article_id');
$this->dbforge->create_table('article2cat');

But I don't see a way of creating a key for two columns.


dbforge add_key - El Forum - 02-11-2008

[eluser]Sean Murphy[/eluser]
Does this work?
Code:
$this->dbforge->add_key('field_1, field_2');



dbforge add_key - El Forum - 02-11-2008

[eluser]Eric Barnes[/eluser]
That sure does and I am not sure why I didn't think about it. Smile

Thank you very much.