I was testing with GC and was testing with relations, between different tables this works great but is this also possible with only one table.
The table contains the following fields.[list]
[*]category_id
[*]category_name
[*]category_parent_id
[/list]
I want to create a form where I can add a category and select another earlier added category as a parent. Is this possible? If so, can anybody tell me how?
Set relation with one table
Started by Bobby Stegwee, 08 August 2012 - 08:41 AM
- Single Page
Posted 08 August 2012 - 08:41 AM
Posted 09 August 2012 - 20:19 PM
Hi Bobeski!
It seems to work for me, even with multiple relations:
Database:
Proof:
[attachment=244:Screen Shot 2012-08-09 at 22.10.10.png]
[attachment=245:Screen Shot 2012-08-09 at 22.09.42.png]
Maybe there's something wrong with your code or database definition. Could you post your code and database?
Greetings,
Nage
It seems to work for me, even with multiple relations:
$crud = new grocery_CRUD();
$crud->set_table('poll_categories');
$crud->set_relation('parent_pollcategoryid','poll_categories','pollcategoryname');
$crud->set_relation('userid','users','username');
$output = $crud->render();
Database:
CREATE TABLE `poll_categories` (
`pollcategoryid` int(11) NOT NULL AUTO_INCREMENT,
`pollcategoryname` varchar(255) NOT NULL DEFAULT '',
`isprivate` tinyint(1) NOT NULL,
`parent_pollcategoryid` int(11) DEFAULT NULL,
`sortorder` int(11) NOT NULL,
`userid` int(11) NOT NULL,
`date_entry` datetime NOT NULL,
`date_updated` datetime DEFAULT NULL,
PRIMARY KEY (`pollcategoryid`),
KEY `key_parent_pollcategoryid` (`parent_pollcategoryid`),
KEY `key_userid` (`userid`),
CONSTRAINT `fk_poll_categories_parent_pollcategoryid` FOREIGN KEY (`parent_pollcategoryid`) REFERENCES `poll_categories` (`pollcategoryid`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_poll_categories_userid` FOREIGN KEY (`userid`) REFERENCES `users` (`userid`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=3000820 DEFAULT CHARSET=utf8;
Proof:
[attachment=244:Screen Shot 2012-08-09 at 22.10.10.png]
[attachment=245:Screen Shot 2012-08-09 at 22.09.42.png]
Maybe there's something wrong with your code or database definition. Could you post your code and database?
Greetings,
Nage