Skip to content
This repository has been archived by the owner on Sep 4, 2022. It is now read-only.

model with recursive reference does not work #31

Closed
yavasura opened this issue Mar 12, 2013 · 7 comments
Closed

model with recursive reference does not work #31

yavasura opened this issue Mar 12, 2013 · 7 comments

Comments

@yavasura
Copy link

CRUD displays a table where region field is not visible. Create new and update works, only list is not working properly

class Model_Region extends Model_Table {
    public $entity_code='region';
    function init(){
        parent::init();
        $this->addField('name')->mandatory('true');
        $this->hasOne('Region');
    }
}
@yavasura
Copy link
Author

quick filter is also not working

@DarkSide666
Copy link
Member

Recursive links never have worked well like that.
You can try some workarounds. For example, use "fake" model, like Model_Region_Parent extends Model_Region and hasOne('Region_Parent','region_id') or something like that.

BTW:

  • In model instead of $entity_code use $table because entity_code is obsolete.
  • Why you reported this in atk4-addons section? CRUD is in atk4 main branch I guess. Or you're talking about some specific CRUD implementation from atk4-addons?

@romaninsh
Copy link
Member

Here is how you define parent as per DarkSides's comment:

class Model_Region_Parent extends Model_Region {
public $alias='region_parent';
}

@romaninsh
Copy link
Member

attempt to add support for this resulted in few big problems with models, so above fix should address the problem.

@DarkSide666
Copy link
Member

Hmm... didn't know that. Will have to try at some point.

BTW Romans, why you're not visible in IRC for last I guess 2 weeks? :)

@yavasura
Copy link
Author

the above code do not work also:

sql looks like this: select SQL_CALC_FOUND_ROWS name,(select name from region where region.region_id = region.id ) region,id,region_id from region order by (select name from region where region.region_id = region.id ) limit 0, 25 []

my code:

class Model_Region extends Model_Table {
public $table='region';
function init(){
parent::init();
$this->addField('name')->mandatory('true');
$this->hasOne('Region_Parent','region_id');
}
}

class Model_Region_Parent extends Model_Region {
public $alias='region_parent';
}

class page_region extends Page {
function init(){
parent::init();
$crud=$this->add('CRUD');
$model = $crud->setModel('Model_Region');
$model->debug();
if($crud->grid){
$crud->grid->addPaginator();
$crud->grid->getColumn('name')->makeSortable();
$crud->grid->getColumn('region')->makeSortable();
$crud->grid->addQuickSearch(array('region','name'));
}
}
}

@DarkSide666
Copy link
Member

Reopened in #33

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants