0

I am not able to set certain tables' scope to publicOnServer. In my model.js, I set the scope for the table. The change in scope can be seen when I view my remote model (4D Database) in Wakanda- the table's scope is updated after my change.

With some tables, when I set the scope and then do any kind of query from the clientside - to any table - the console on my browser fills with errors and the query fails. Effectively, setting certain tables' scope in model.js breaks query for even an unrelated table.

One difference I notice between the tables for which scope changes work and those where it doesn't are tables that have relational attributes. Setting the scope for these tables consistently breaks query functionality and setting scope for tables without relational attributes consistently works fine. Is this a bug?

Chrome console output: ERROR Error: Uncaught (in promise): Error: Needed Contractor dataClass is not present on catalog

Line in model.js: model.Contractor.properties.scope="publicOnServer";

Contractor is a table in the remote model and it has relational attributes.

NAMS
  • 983
  • 7
  • 17

1 Answers1

1

I ran the solution and based on the model of your project. This is a standard behavior and the error is expected. Any data class that is set to "PublicOnServer" is considered "removed" or "hidden" from client-side. Relation attribute in other class referencing this class is considered error just like it is referencing a non-exist class. The error will not appear if the Books class is set to "PublicOnServer" since it is not related to any other class.

If you click the first line in the error stack: wakanda-client.no-promise.js line: 1880. You will find the following code:

//Check if we have all needed dataClasses on the catalog
for (var _e = 0, _f = _this.seenDataClasses; _e < _f.length; _e++) {
    var dcName = _f[_e];
    if (!catalog[dcName]) {
       throw new Error('Needed ' + dcName + ' dataClass is not present on catalog');
    }
}

at line 1775 you will find a function neededDataClass() comparing array called seenDataClasses with data classes need.

Wakada client framework in fact promptly checks all public data classes and examine whether they have relational attributes that are referencing a non-public data class. This will avoid future problems in subsequent queries.

The error "Errors in the console disappear if solution is launched without restricting access to the Company table." is added by Wakanda client in the promise to stop you from querying Client table containing an invalid relation attribute. I recommend adding a catch() in your code to handle it:

wakanda.getCatalog()
    .then((ds) => {
        this.ds = ds;
    }).catch(error=>{
        //handle the error
}); 

Previous Answer:

In my understanding, when the related table of the table you are querying is set as "publicOnServer", the query will work as long as the related table is not referenced in the query string or in query results subsequently.

Can you provide a reproducible example of your model and code containing query string?

Xiang Liu
  • 393
  • 1
  • 7
  • Yes- link below. Actually, just getting the wakanda catalog causes the error. Don't even need to query. https://www.dropbox.com/s/85pr5svswpi6m07/TableScope.zip?dl=0 – NAMS Oct 20 '17 at 15:30
  • I understand, thank you. This behavior differs from Wakanda 1.x which is why I was surprised. I thought of a workaround, where I will leave all tables public and write restrict (etc) methods for all tables accordingly. – NAMS Oct 25 '17 at 18:58
  • IMO using permission control and restricting query might be the better solution if there are more than two user groups that have different permissions. There is a [2016 summit session on KB](http://kb.4d.com/assetid=77627) covering it. Most of the server implementation would still apply in V2 – Xiang Liu Oct 25 '17 at 22:31