- Model API (properties, scope, relations)
- Custom login
- Extended class
- Restricting query
- Start solution
- Run "CREATE_TEST_DATA"
- Confirm that entities are created
- Open Data Browser
- Confirm that only WAF* classes are visible, and no entites are displayed
- Open index.waPage
- Login with user name (created in CREATE_TEST_DATA) and "asdf" (hard-coded in required.js)
- Confirm that only the user's data is visible.
- Logout
- Confirm that no data is visible
You might concider creating a relatedEntities attribute on the extended "1" class, which links to a relatedEntity attribute on the the extended "N" class.
The restricting query of the derived N class will look like this:
model.WAFProduct.events.restrict = function(e){
return ds.WAFUser.products;
}
i.e. Execute the restring query on the extended 1 class and create a restricted collection by following the relation path.
But this is WRONG!!!
In Wakanda, you can add a relatedEntities attribute to an extended class, but NOT a "relatedEntity" attribute, which needs to store the primary key of its related 1. In effect, it is a kind of a storage attribute. As such, the relatedEntities attribute must exist on the original class.
- Before:
model.WAFProduct.user = new Attribute('relatedEntity',
'WAFUser',
'WAFUser',
{
'scope':'public'
});
- After:
model.Product.user = new Attribute('relatedEntity',
'WAFUser',
'WAFUser',
{
'scope':'public'
});
Note: This is a link from a "publicOnServer" class to a "public" class, but it is OK, because the relatedEntity (Product.user) atrribute is "public", which means it is inherited by the derived class (WAFProduct.user).
If you decide to work with the original classes, on the server side, keep in mind that the data type of the foreign key is an extended class (WAFUser), which means you can't assign it's original class to create a related entity.
var product = new ds.Product();
product.user = ds.User(1);//WRONG!!! data type is not User
product.user = ds.WAFUser(1);//WRONG!!! the restricting query will apply
product.user = ds.User(1).id;//GOOD
It is good practice to update the page after login, and clear the cache after logout.
login1.logout = function login1_logout (event)
{
sources.user.all();
};
login1.login = function login1_login (event)
{
ds.WAFProduct.clearCache();
sources.user.all();
};