Jump to content


Set_relation where with same table

set_relation where

  • Please log in to reply
1 reply to this topic

#1 Kobus

Kobus

    Advanced Member

  • Members
  • PipPipPip
  • 74 posts
  • LocationSouth Africa

Posted 11 June 2014 - 06:47 PM

Hi guys,

 

I hope you are all well. I urgently need your help please - I am either very stupic, or GC cannot do what I want to do.

 

I have a table called categories, that has the following "ancestors" in the same table.

 

id = PK

parent_id (FK in same table)

grandparent_id (FK in same table)

 

Reason why they are in the same table is because each item can have max one parent and max one grandparent. Most, however, will not have a grandparent. Here is an example:

 

WITH GRANDPARENT:

 

There are 55 notebooks (e,.g., HP 250 i3, HP 250 i5), within category "HP 250 Series", which is the child of category "HP" which in turn is the child pf "Notebooks", thus the tree is: "Notebooks -> HP -> HP 250 -> HP 250 -> HP 205 i3"

 

WITHOUT GRANDPARENT

 

There are 436 other components, spread into 93 categories, such as "Printers", "Scanners" and "Hard drives", which are children of category "Components", thus the tree is: "Components -> Printers -> Some Printer"

 

I have realized due to the difference in the structures that I would need two cruds. One to manage the notebooks, and one to manage the other categories.

 

So: manage_notebook_categories looks right, and is something like this:

                $crud->where(config_item('db_prefix') . 'categories.grandparent_id =', 289);
                $crud->set_relation('parent_id', config_item('db_prefix') . 'categories', 'title', array('parent_id' => 289));
                $crud->field_type('grandparent_id', 'hidden', 289);

In the relation, I need the parent_id and not the grandparent_id, because I want only the children of "notebooks" category (ID: 289) to be chosen as its parent. But in the list, I need the grandparent_id, because I need to display every laptop that falls in any laptop category, which has the grandparent of 289. All sorted, but the problem is with the manage categories.

 

 

And: manage_categories does not work, looks something like this:

                $crud->where(config_item('db_prefix') . 'categories.grandparent_id =', 0);
                $crud->set_relation('parent_id', config_item('db_prefix') . 'categories', 'title', array('parent_id' => 0));
                $crud->field_type('grandparent_id', 'hidden', 0);

I do not understand why the second one does not work. It must list ALL that have a grandparent_id of 0 (thus excluding notebooks, which are the only ones with grandparent_id not equal to 0), and when editing, choosing a parent, it has to take only the categories that has a parent_id of 0 (thus the root of components), as described above. In the second crud, the parent selection is empty, no matter what I try.

 

I hope someone can urgently help - I am really clueless as to what is going wrong here.

 

Thanks!

 

Kobus

 

 

 

 

 

 


--------------------
Kobus Myburgh
Managing Director: Impero Consulting
http://www.impero.co.za
+27 82 043 8488


#2 Kobus

Kobus

    Advanced Member

  • Members
  • PipPipPip
  • 74 posts
  • LocationSouth Africa

Posted 11 June 2014 - 06:50 PM

Sorry for triple post, everyone. My browser got stuck somehow... :-(


--------------------
Kobus Myburgh
Managing Director: Impero Consulting
http://www.impero.co.za
+27 82 043 8488






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users