diff --git a/ckan/model/group.py b/ckan/model/group.py index b0c1c22fba5..fc3c5b17b30 100644 --- a/ckan/model/group.py +++ b/ckan/model/group.py @@ -404,7 +404,7 @@ def __repr__(self): WHERE m.table_id = c.group_id AND m.table_name = 'group' AND m.state = 'active' ) -SELECT G.*, child.group_id as parent_id FROM child +SELECT G.*, child.table_id as parent_id FROM child INNER JOIN public.group G ON G.id = child.group_id WHERE G.type = :type AND G.state='active';""" diff --git a/ckan/tests/models/test_group.py b/ckan/tests/models/test_group.py index 13cee1907dc..3c6973b8b40 100644 --- a/ckan/tests/models/test_group.py +++ b/ckan/tests/models/test_group.py @@ -116,6 +116,15 @@ def test_get_children_groups(self): assert_in(res[0]['name'], ('national-health-service', 'food-standards-agency')) assert_in(res[0]['title'], ('National Health Service', 'Food Standards Agency')) + def test_get_children_group_hierarchy__from_top_2(self): + groups = model.Group.by_name(u'department-of-health').\ + get_children_group_hierarchy(type=group_type) + # the first group must be NHS or Food Standards Agency - i.e. on the + # first level down + nhs = groups[0] + assert_in(nhs[0].name, ('national-health-service', 'food-standards-agency')) + assert_equal(model.Group.get(nhs[1]).name, 'department-of-health') + def test_get_children_group_hierarchy__from_top(self): assert_equal(name_set_from_group_tuple(model.Group.by_name(u'department-of-health').\ get_children_group_hierarchy(type=group_type)),