Virtual Field that uses data from hasMany associated table

Hello everybody,

I know well that one can create a virtual field name for an entity like this: Entities - 4.x

Imagine, I have two tables:

Activity [‘id’, ‘type’, ‘legaldefinition_id’]


Legaldefinition [‘id’, ‘fulldefinition’]

I would like to set display field for my activity table to something like this:


using the virtual field function in my activity.php entity:

protected function _getTypeFulldefinition()
return $this->type. ‘__’ .$this->$fulldefinition;

Is it possible for typical hasMany associations?

Thanks a lot in advance!

A few issues here. I’ll start with the most critical. If it’s a hasMany association, there shouldn’t be a singular property, but rather a plural one, which would be an array. I think you want a hasOne or belongsTo association?

Now, let’s assume that it really is just a singular association from Activity to Legaldefinition. The property you’d want to access is then not $this->fulldefinition (and definitely not $this->$fulldefinition as you wrote) but rather $this->legaldefinition.

And $this->legaldefinition would be an object, not a string, so what you really really want is actually $this->legaldefinition->fulldefinition.

Thank you very much @Zuluru. I will try that.