Skip to Content

CAPM - Performing CRUD operations on Views

Hi Experts.

Over the last few weeks I have been messing around with CAPM by building out a simple Doctor / Patient appointment booking scenario. Coming from a CRM background, my aim is to essentially test the Business Partner concept with CAPm whereby a person can take on multiple roles (i.e. a doctor can be a patient) and we need to normalise the data model do avoid replication of say Name, Surname etc.

In my scenario I have:

  • a persons-model.cds file in the /db folder which i have normalised into {Business_Partner, Business_Role, Patient, Practitioner} where Patients have business role "02" and Practitioners have the role "01"
  • a admin-service.cds file in the /srv folder which contains the Patient and Practitioner entities which are SELECTS across {Business_Partner, Business_Role, Patient} and {Business_ Partner, Business_Role, Practitioner} respectively

From what I understand (and what I observe from the database) is that the /srv Patient and Practitioner entities are generates as views. Consequently i am able to read Patients and Practitioners, but i am unable to perform Create, Updates or Delete operations.

What is the recommended approach form performing CRUD operations on entities that are views.

Any help will be appreciated

DJ Adams Christian Georgi Gregor Wolf

repo: https://github.com/scongia/theatremate.git

Add a comment
10|10000 characters needed characters exceeded

  • Maybe Gregor Wolf can help to answer the question? Thanks a lot.

  • ..update..

    I noticed that of you remove the "db" module from package.json, and only leave the "srv" module, then cds will generate the database with the views that are defined in srv/admin-service.cds. Additionally, cds will generate an additional "db" module and insert it after the "srv" module. The views are not generated if "srv" were "db"

    Before npm run setup

      "scripts": {
        "setup": "npm install && npm run deploy",
        "deploy": "cds deploy srv --to sqlite:db/theatremate.db",
        "start": "cds run"
      },
      "cds": {
        "requires": {
          "srv": {
            "kind": "sqlite",
            "model": "srv",
            "credentials": {
              "database": "db/theatremate.db"
            }
          }
        }
      }<br>

    After num run setup ("db" module inserted by cds)

      "scripts": {
        "setup": "npm install && npm run deploy",
        "deploy": "cds deploy srv --to sqlite:db/theatremate.db",
        "start": "cds run"
      },
      "cds": {
        "requires": {
          "srv": {
            "kind": "sqlite",
            "model": "srv",
            "credentials": {
              "database": "db/theatremate.db"
            }
          },
          "db": {
            "kind": "sqlite",
            "model": "srv",
            "credentials": {
              "database": "db/theatremate.db"
            }
          }
        }
      }<br>

    Database contains view defined in srv/admin-service.cds

  • To check this on your end, delete the sqlite database after you have changed the package.json and then call npm run setup

Related questions

0 Answers

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.