Search code examples
2sxc

Field with Query based entity Data Type based on Entity from other App


Goal

I want to centralize Person based information within one 2sxc App and reuse the 'Persons' within other App's. Like a Person as an Author within a News-App and a Person as member within a Team-App and so on.

What I did

Create an App for Person administration (NPi_Person):

  • Define a Person Content-Type with Fields like 'FullName', 'Phone' and so on.

In another App, for example an App for News (NPi_News):

  • Define within the News Content-Type a Field Person_Entity with Datatype Entity and Input Type Query based entity/item-picker.
  • Create a Query with DataSource App based on NPi_Person, retrieving the Content-Type Person (query_Person_from_NPi_Person).
  • In entity-query definition of the Person_Entity Field refer to query_Person_from_NPi_Person and to the Stream (e.g. Default).

Problem

The dropdown of the Field Person_Entity of the NPi_News App contains as expected the Person Entities from the NPi_Person App. The problem is that the Person Entity doesn't get persisted. Means after saving and reopening the Form the Field Person_Entity is still empty.

Does this mean that the source of a Field with Datatype Entity and Input Type Query based entity/item-picker may not derive from another App?


Solution

  • the entity field has relationships which are verified when loading the app into the cache. Each app is self-contained, so relationships are verified within that app only.

    Entities from another app may or may not exist - it's something you must handle at runtime.

    So to store these, you'll have to use the string-query and then look them up in your cshtml from the other app (or you can probably also do this using a query which looks them up from the string keys). It's also super-fast, but you need to manually do this as you're going beyond the default data-model.