cancel
Showing results for 
Search instead for 
Did you mean: 

CAP CDS: association from entity with persistence.skip

daniel_mangold
Explorer

Hello,

I needed an entity annotated with @cds.persistence.skip where the output is fully calculated in the handler.

Now, from the non-persistent entity it would be great to still be able to have an association to a usual, persisted entity. The main reason for that being Fiori Element navigations, otherwise we would have to do a freestyle implementation which is more effort and would not really be required.

It is straight forward to model it in cds and everything starts up properly but on request, I get a runtime error (SQLITE_ERROR: no such table:), so it seems that CAP wants to join to persistent table with the calculated entity where no table exists.

Is there any annotation or something to get around this?

Thanks,

Daniel

Example (might have syntax errors, just to make the idea more visual):

entity PersistedEntity {
 key mykey: Integer,
     anyField: String
}

@cds.persistence.skip
entity TransientEntity {
 key mykey: Integer,
     anyCalculatedField: String,
     anyForeignKey : Integer,
     persisted : Association to PersistedEntity
                    on  persisted.anyField = $self.anyForeignKey
}

gregorw
Active Contributor
0 Kudos

How does your READ handler implementation look like?

daniel_mangold
Explorer
0 Kudos

I think I got it running. Will post the solution soon (also the read handler), then you can maybe comment if it makes sense or if there is a better way to do it.

Accepted Solutions (0)

Answers (1)

Answers (1)

michaelschmid03
Explorer
0 Kudos

Its been 2 years but i thought why shouldnt i answer anyway? Perhaps it might help someone

These annotations seem correct (on first glance, i havent tested) and should work properly.

Heres where you went wrong: the annotation "@cds.persistence.skip" won't modify whatever query you send to your Remote Service / Database. 

For this you would need to implement your own custom Handler:
something like this if you know what i mean

 

this.on("READ", "TransientEntity", async (req) => {
  let oTransientEntity=this.calculateYourTransientEntity() //returns{anyCalculatedField:"Value"}       
  let oPersistedEntity=await cds.run(Select(["anyField"]).from("PersistedEntity"))
  oTransientEntity.persisted=oPersistedEntity
  return oTransientEntity     
});