MVC Grid showing relation twice

52 views
Skip to first unread message

Gowrav

unread,
May 21, 2012, 8:32:36 AM5/21/12
to agile-too...@googlegroups.com
HI,
I have a model like

class Model_Fee extends Model_Table {
    var $table='jos_xfee';
    function init(){
        parent::init();
        $this->addField('name')->mandatory('Fee Head Should have a name');
        $this->addField('amount')->type("money")->mandatory("Fee Amount should be entered");
        $this->addField('isOptional')->type('boolean');
        $this->hasOne('Fee_Head','feehead_id');
        $this->hasOne('Class','fee_class_id');
//        $this->debug();
    }
}

and a MVCGrid on a page like this

        $g=$this->add('MVCGrid');
        $m=$g->setModel('Model_Fee');

but then grid shows two feeheads (one with Id and one with Name due to relation) and two classes

if I destroy feehead_id field both are removed..

any solution ...

Romans Malinovskis

unread,
May 21, 2012, 6:31:57 PM5/21/12
to agile-too...@googlegroups.com

Hi Gowraw

hasOne creates a new field of class Field_Relation. It’s method destruct() will remove the feehead field also, to avoid any field referencing the feedead_id field.

You should rather hide the field and there are several ways to do that:

1) ->visible(false) - will hide field from the grid and from the select
2) ->system(true) - will hide the field from the grid, but would have it in the query regardless.
3) $grid->setModel(‘Fee’, array(’name’,’amount’,’isOptional’));  - explicitly sets which fields to display. All of the named fields must be present and be visible. This also affects the order in which columns appear.
4) you can manually add columns. $grid->setModel(‘Fee’, false); will only initialize controller. You can subsequently call $grid->controller->importField(’name’); which will initialize column.

romans


--
FYI: If amount of emails you receive from this group is too much - switch to "Digest" mode. You'll receive no more than 1 email per day.
 
To post to this group, send email to
agile-too...@googlegroups.com
 
To unsubscribe and view archive:
http://groups.google.com/group/agile-toolkit-devel?hl=en
 
To download Agile Toolkit, visit:
http://agiletoolkit.org/

Reply all
Reply to author
Forward
0 new messages