Parse: Retrive all Objects where user is in a relation - parse-platform

I have a Parse Object Event it contain a key attendees, a Parse Relation object. My question is how to retrieve all event where current user is in the attendees relation ? my current code is :
var query = new Parse.Query(Event).equalTo('attendees',currentUser)
query.find({
success:function(list){
}
})

Your query seems Ok, try to verify your data in DB.
cmd from mongo shell
db.getCollection('_Join:attendees:Event').find({'relatedId':currentuserId})

Related

Undefined property $id for users. But user has ID

I'm attempting to build up a query in Laravel.
I have two tables, with the following attirbuteds
User
id (auto)
name
email
userType
password
TenantPreferance
id (auto)
county
type
user_id (this is the user who created their
preference)
I'm trying to get a collection of data from users of a certain type where id of the user, matches the user_id in preferences.
But I get this error
Undefined property: Illuminate\Database\Eloquent\Builder::$id
$tenants = User::where('userType', 'tenant');
$Prefereances = TenantPreferance::where($tenants->id, $Prefereances->user_id);
$users = $Prefereances->get();
for : $tenants = User::where('userType', 'tenant');
must add:
first()
$tenants = User::where('userType', 'tenant')->first();
or : get()
$tenants = User::where('userType', 'tenant')->get();
You need to actually run the built sql. You also need to get a singular event of it out. So im using first() in this instance. Like this
$tenants = User::where('userType', 'tenant')->first();
$tentants = User::with('TenantPreferance')->where('userType', 'tenant')->get();
where TenantPreferance is the relationship name

Retrieve Customer Entity in Dynamics CRM 2016

As we know Dynamics CRM has a specific attribute value: Customer. This value combines the Client and Account entity, but I'm blind or MSDN doesn't have specification about retrieving this field in query.
For example:
QueryByAttribute query = new QueryByAttribute(entName);
query.ColumnSet = new ColumnSet(new String[] { searchAttr });
query.Attributes.Add(searchAttr);
query.Values.Add(searchValue);
EntityCollection retrived = service.RetrieveMultiple(query);
This code accepts entity name and searches the attribute's name and value, but when I run it I don't know which type of entity I get from my DataSouce: Client or Account.
So the question is: is it possible to retrieve Customer entity in one query?
No, you must first know which entity you are trying to retrieve.
Get the value held within the Customer field as an EntityReference:
var customer = entity.GetAttributeValue<EntityReference>("customerid");
Get the LogicalName of the EntityReference:
var customerEntity = customer.LogicalName;

Getting objects from Parse Relation that were added in this save

I have a Parse Class Group and there is a parse relation field in it, called people (users, who are in this group). I am implementing a afterSave on "Group". I want to notify users, who are just added by admin into this group.
How do i do that ?
Parse.Cloud.afterSave(Group, function(request){
Parse.Cloud.useMasterKey();
var group = request.object;
var relation = group.relation("people");
//How to get users that are added on this save.
});
To find the new records being added to a relation, you need to inspect the relationsToAdd property of a Relation (its an array):
var newRecords = request.object.op("people").relationsToAdd;
I know this works in beforeSave but have not used it in afterSave tirggers

Parse join table relation

I have the same case that is used in the Parse documentation for many-to-many relations using a join table.
In my case I am fetching a list of users by a simple query, but what I need is to know if current user following the user in the list, meaning I want to add a button to the list of users that allows the current user to follow or unfollow users in the list based on their following status.
Is there any chance that I can get this info with one query?
this will help you. see Relational Queries
var following = Parse.Object.extend("Following"); //Following (ParseObject)
var currentUser = Parse.User.current();
var innerQuery = new Parse.Query(following);
innerQuery.exists("status");
var query = new Parse.Query(currentUser);
query.matchesQuery("follow", innerQuery); //follow is pointer type
query.find({
success: function(comments) {
}
});

Parse Android: update ParseObject containing an array of ParseUsers throws UserCannotBeAlteredWithoutSessionError

im working on an Android App.
I have a custom class which has relations with TWO ParseUsers and other fields. As suggested by the docs, I used an array (with key "usersArray") to store the pointers for the two ParseUsers, because I want to be able to use "include" to include the users when i query my custom class. I can create a new object and save it successfully.
//My custom parse class:
CustomObject customObject = new CustomObject();
ArrayList<ParseUser> users = new ArrayList<ParseUser>();
users.add(ParseUser.getCurrentUser());
users.add(anotherUser);
customObject.put("usersArray", users);
//I also store other variable which i would like to update later
customObject.put("otherVariable",false);
customObject.saveInBackground();
Also, i can query successfully with:
ParseQuery<CustomObject> query = CustomObject.getQuery();
query.whereEqualTo("usersArray", ParseUser.getCurrentUser());
query.whereEqualTo("usersArray", anotherUser);
query.include("usersArray");
query.findInBackground( .... );
My problem is when trying to UPDATE one of those CustomObject.
So after retrieving the CustomObject with the previous query, if I try to change the value of the "otherVariable" to true and save the object, I am getting a UserCannotBeAlteredWithoutSessionError or java.lang.IllegalArgumentException: Cannot save a ParseUser that is not authenticated exceptions.
CustomObject customObject = customObject.get(0); //From the query
customObject.put("otherVariable", true);
customObject.saveInBackground(); // EXCEPTION
I can see this is somehow related to the fact im trying to update an object which contains a pointer to a ParseUser. But im NOT modifying the user, i just want to update one of the fields of the CustomObject.
¿There is any way to solve this problem?
Maybe late but Parse users have ACL of public read and private write so you should do users.isAuthenticated() to check if its true or false.
If false then login with the user and retry. Note: you cannot edit info on two users at the same time without logging out and relogging in.
Another thing you can do is use Roles and define an admin role by using ACL which can write over all users.

Resources