getting additional fields from a model with hasOne relation

63 views
Skip to first unread message

Willem Rheeder

unread,
Nov 22, 2012, 3:29:22 PM11/22/12
to agile-too...@googlegroups.com
Hi,

I have a model with a hasOne relation to another model..
$def_group = $this->hasOne('Defgroup','defgroup_id','kod')->mandatory('DefGroup Required')->Caption('Kod');

In a Crud I now get 'kod' from this table.  How do I manage to get other fields from the DefGroup table?

Regards,
Willem

Ernesto Turco

unread,
Nov 23, 2012, 4:46:47 AM11/23/12
to agile-too...@googlegroups.com
In this way you create only a field combobox.
If you need more fields of the table Defgroup should do a join.
Try this:


$defgroup = $this->join('defgroup.defgroup_id','kod');
$defgroup->addField('other_field_defgroup')->caption('Label');

Willem Rheeder

unread,
Nov 23, 2012, 6:56:01 AM11/23/12
to agile-too...@googlegroups.com
Hi Ernesto,

Thanx, with your help I managed to display all the required fields in the CRUD.

Can you maybe help me with one more thing.  If I now edit a record of this CRUD  I want Kod to be combobox again and Opis basically to reflect Opis for the Kod selected.

Is it possible?

cuurent code in model:
                $def_group = $this->join('DefGroup');
$def_group->addField('kod');
$def_group->addField('opis');

Regards,
Willem

Ernesto Turco

unread,
Nov 23, 2012, 7:44:55 AM11/23/12
to agile-too...@googlegroups.com
but do you need that Opis changes according to kod change?


Il giorno giovedì 22 novembre 2012 21:29:22 UTC+1, Willem Rheeder ha scritto:

Willem Rheeder

unread,
Nov 23, 2012, 7:47:00 AM11/23/12
to agile-too...@googlegroups.com
yes.  Kod is like the main lookup field, fetching everything from defgroup for that kod.


On Thursday, November 22, 2012 10:29:22 PM UTC+2, Willem Rheeder wrote:

Willem Rheeder

unread,
Nov 23, 2012, 8:07:30 AM11/23/12
to agile-too...@googlegroups.com
I failed to mention that this should happen when you edit in CRUD.



On Thursday, November 22, 2012 10:29:22 PM UTC+2, Willem Rheeder wrote:

Ernesto Turco

unread,
Nov 23, 2012, 2:15:31 PM11/23/12
to agile-too...@googlegroups.com
I don't know if this feature exists.
Waiting for response from someone more experienced.
It's interesting to me too! :-)


Il giorno giovedì 22 novembre 2012 21:29:22 UTC+1, Willem Rheeder ha scritto:

Willem Rheeder

unread,
Nov 23, 2012, 2:51:43 PM11/23/12
to agile-too...@googlegroups.com
Thank you very much, looking forward to hearing if this is possible. I have been surprised by the toolkits versatility so much already, I won't be surprised if there is a easy way of achieving this, I think solution might be similiar to the autocomplete addon.

Regards,
Willem
Sent from my BlackBerry®
________________________________
From: Ernesto Turco <turcoe...@gmail.com>
Sender: <agile-too...@googlegroups.com>
Date: Fri, 23 Nov 2012 11:15:31 -0800
To: <agile-too...@googlegroups.com>
ReplyTo: <agile-too...@googlegroups.com>
Subject: [atk4] Re: getting additional fields from a model with hasOne relation
--



Janis Volbergs

unread,
Nov 26, 2012, 1:04:27 PM11/26/12
to agile-too...@googlegroups.com
It depends on your intentions. But here is what you can do:

class Model_X extends Model_Table {
function init(){
parent::init();

$this->addField("name");
                $this->hasOne("Defgroup", "defgroup_id", "kod");

/* if you need more than one field in your model */
$def_group = $this->leftJoin("defgroup");
$def_group->addField("kod");
$def_group->addField("kod2");
$def_group->addField("kod3");
}
}


--
 
 

Gowrav Vishwakarma

unread,
Nov 26, 2012, 10:31:47 PM11/26/12
to agile-too...@googlegroups.com
You can also addCondition(s) on these fields but remember the conditions on joined table field will be only applicable when you are reading(select query) but when updating to model the conditions on these join field will not be in effect... at least as per right now git master.

--
 
 



--
Regards

Gowrav Vishwakarma
Man of Affairs, Digital Vish, Xavoc International
http://www.digitlavish.com : +91 9783807100
http://www.xavoc.com

--------------------------------------------------------------------
Never Never Never Never Never Never Never Never Never Never Never Never Never Never Never  GIVE UP

Imants Horsts

unread,
Nov 27, 2012, 3:35:24 AM11/27/12
to agile-too...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages