Adding a virtual field that is processed by converters and by extract()

19 views
Skip to first unread message

Eric Risler

unread,
Mar 19, 2014, 5:29:38 PM3/19/14
to pommp...@googlegroups.com
It is possible to add a user defined field to a map/entity that does not exist in the table database but is processed by the extract() method and any registered converters?

Example:
I have a location entity that I wish to add a service_date field too. This field is not in the database. Its value is calculated based on other field values:

Location (entity):
- I add a custom getter called getServiceDate() that returns a timestamp after performing calculations based on other entity fields.

LocationMap (map):
- initialize()
   - call $this->addField('service_date', 'timestamp');

- getSelectFields()
  - call unset($fields['service_date']); so the field is not used in database queries.

Outcome:
- If I call $entity->extract(), the custom getter is not called.

Grégoire Hubert

unread,
Mar 19, 2014, 7:35:20 PM3/19/14
to pommp...@googlegroups.com
Good catch !

I open a github issue.

--
Grégoire HUBERT
Pomm : http://www.pomm-project.org

Grégoire Hubert

unread,
Mar 19, 2014, 7:44:51 PM3/19/14
to pommp...@googlegroups.com
Calling addField() is not necessary here since it defines the default
values for getSelectFields().

Eric Risler

unread,
Mar 19, 2014, 9:19:05 PM3/19/14
to pommp...@googlegroups.com
I realize that if I call addField() that the field is included in the getSelectFields(). I don't want this of course, but I do want my custom field to be included in extract() calls on the entity. I tried calling addVirtualField() but the field was not included in extract() either.

ER

Grégoire Hubert

unread,
Mar 20, 2014, 7:43:59 AM3/20/14
to pommp...@googlegroups.com
Yes, addField() and addVirtualField() do manage the default projection
of the mapper accordingly with the converter system. The problem here
is how entities dump out their data.

A discussion is open about this: https://github.com/chanmix51/Pomm/issues/129
> --
> You received this message because you are subscribed to the Google Groups
> "PommProject" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pommproject...@googlegroups.com.
> Visit this group at http://groups.google.com/group/pommproject.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages