This question is locked. New answers and comments are not allowed.
Hi,
I've been trying to figure out how to set a relation within the beforeCreate Event to set relational fields within my Backend.
An Example:
- Two tables: Offers and Companies
- Offers contains a field with a relation to Companies
- Offers contains another field which entry corresponds to a unique entry within Companies (e.g Website)
- The client side App will now insert a new Offer providing the Website and further informations
- The Cloud Code should now find the entry in Companies which corresponds with the provided Website
- The Cloud Code uses the result to set the relation within the Offers table (for sure in this case the Id of the Companies table)
I figured out how to find the corresponding Companies entry using following within the beforeCreate Event:
var filter = { 'Website' : request.data.Website};
Everlive.Sdk.$.data('Companies').get(filter,
function(error, data)
{
if (error)
{
// do error handling
}
else
{
request.data.Company = data.result.???;
}
});
This code returns the data result containing all information about the Companies entry but I'm not sure how to access the Id to add it to my request object using the lines request.data.Company = data.result.???
Using a hardcoded version works but makes no sense ;) (e.g. request.data.Company = "669068d0-b445-11e3-bf0b-e3a3bc3e3d68"
I also tried using the new EverliveSDK.Query() object getting an error like: Query() is not a function of ...
Furthermore I would be interested how to use query filters in Cloud Code to minimize the query results to specific fields.
Any help is welcomed and maybe I just miss the forrest for the trees.
Thanks and regards
I've been trying to figure out how to set a relation within the beforeCreate Event to set relational fields within my Backend.
An Example:
- Two tables: Offers and Companies
- Offers contains a field with a relation to Companies
- Offers contains another field which entry corresponds to a unique entry within Companies (e.g Website)
- The client side App will now insert a new Offer providing the Website and further informations
- The Cloud Code should now find the entry in Companies which corresponds with the provided Website
- The Cloud Code uses the result to set the relation within the Offers table (for sure in this case the Id of the Companies table)
I figured out how to find the corresponding Companies entry using following within the beforeCreate Event:
var filter = { 'Website' : request.data.Website};
Everlive.Sdk.$.data('Companies').get(filter,
function(error, data)
{
if (error)
{
// do error handling
}
else
{
request.data.Company = data.result.???;
}
});
This code returns the data result containing all information about the Companies entry but I'm not sure how to access the Id to add it to my request object using the lines request.data.Company = data.result.???
Using a hardcoded version works but makes no sense ;) (e.g. request.data.Company = "669068d0-b445-11e3-bf0b-e3a3bc3e3d68"
I also tried using the new EverliveSDK.Query() object getting an error like: Query() is not a function of ...
Furthermore I would be interested how to use query filters in Cloud Code to minimize the query results to specific fields.
Any help is welcomed and maybe I just miss the forrest for the trees.
Thanks and regards