Relational data query in Parse - retrieve users with and without messages - parse-platform

I have a relation on user in Parse 'messages'
I want to issue a query via cloudcoud that retrieves all friends of user (another relation, friendship) AND messages if there are any messages where the current user is the recipient.
I got this far:
var relation = current.relation("friendship");
var queryRel = relation.query();
queryRel.select("username","color","count");
queryRel.ascending("username");
var innerQuery = new Parse.Query("Message");
innerQuery.equalTo("recipient",current);
queryRel.matchesQuery("messages", innerQuery);
...but that only retrieves friends of the current user who have messages, not those who are friends but don't have messages. I need both!
If at all possible, I also want to retrieve the messages themselves, not just pointers. This is all so I can return properly organised data to the client so my apps don't have to do lots of looping to sort things.

I would use the include method here. The way it works is you would do queryRel.include("message"); so you won't just get the pointers. I believe you should also remove the second query for this to work.
The above code is assuming your column pointing to the Message table is called "message"

Related

DynamoDB Appsync Query on multiple attributes

My app uses AppSync resolvers to fetch data from DDB and return it to our front-end. One table we have is for Notifications. A Notification can be either pending or default (non-pending). The table itself has a primary key of notification_id and we have a GSI called userIndex to grab the notifications for a user, with a sort key of timestamp.
In the app, I show all notifications in a list, pending first and then default. Given that a user may have many notifications, I'd like to implement pagination to fetch a batch at a time. The only way I've been able to do this is to
change the query to include a isPending parameter, which I use as a filter expression for the query to only return notifications that are isPending or isNotPending.
Store two "nextTokens", one for each isPending and isNotPending, along with corresponding lists.
Make separate queries for pending/non-pending, and use the filter to return to the appropriate list.
This is obviously inefficient and I am re-reading data from DynamoDB. My question is, given my DynamoDB table/requirements, is there a way I can paginate so that I can get all the pending notifications first (sorted by timestamp) and then all the default notifications next (sorted by timestamp) by using one query and one nextToken
I've seen the use of #model and #key, but I haven't been able to make it work in my app.
Thanks!
No, not really. There is a hard limit on returns for a Dynamodb query - and that cannot be bypassed. the only way to make use of nextToken is another query.
However, it is also worth noting that the FilterExpression happens after the data has already been retrieved and is filtered client side. It does not reduce the documents pulled from the query - only whats displayed. So the next token is still going to be (relatively) the same for each query. You can instead filter it yourself after the call before the next pagination query and save yourself a little bit in terms of multiple calls.

Don't show the message to all users? ( laravel )

I need to create to send a message to all new users registered on my website. I created a table called messages that admins can store (insert) the messages from the admin panel to this table and these messages are simply shown to all users with a foreach.
I don't know if this the best way to do something like that!
Anyway, the problem is that when any new user register and open his dashboard he just found the old messages
This is the table :
image
And this is the simple code for foreach
$msgForAll = Message::latest()->get();
I'm not sure how to display new messages to the users.
Again the way I made this idea is wrong, I know that ):
You can use eloquent's where spefically the whereDate queries in your case to get certain rows past or before date.
As an example relating to what you want to do, it can be along the lines of this:
// Given that you are using Auth to get the user's data...
// Get messages that were created after the user's creation date
$messages = Message::whereDate('created_at','>',Auth::User()->created_at)->get();

Is it possible and how to perform a join like operation which relies on the results of another observer

Sorry but I am very new to RxJS but I am getting the hang of it slowly but one question I just cant seem to get an answer for this could be the way I am wording the question but here goes...
Lets say I have a table called users, this table is keyed via the users unique pushed key (so it unique!). I create a ref to it i.e '/users/' + id, and as expected I get my record for the user which contains a field called 'nurseryId', great just what I wanted!
The problem is and this is where it may be my understanding of RxJS, but I want to use the 'nurseryId' from within the 'users' record but to do this I need to create another ref to the '/nurseries/' + nurseryId table, how can I do this from within the users observable? Is it even possible?
I dont want to combine the two pieces of information and I want to create a route resolver but I need the results from the first fetch before I can start the second fetch???
Many thanks in advance!
You have to subscribe to the 'user' ObjectObservable.
userObject.subscribe(userSnapshot=>{
//query here with userSnapshot.nurseryId as parameter
}

How to query for objects which has certain parse objects contained in a relation

I have a messaging system in Parse, a Message class and a User class. Each Message has a relation called senders to multiple users.
How do I query for all messages for a single user?
This query should give the expected result:
var query = new Parse.Query('Message');
query.equalTo('senders', user);

Validation function to ensure unique field in couchdb

Is it possible to write a validation function to ensure a field of a new document is unique?
Imagine I'm trying to write a validation function that does not allow for two users to have the same email. Every time I create a new user, the validation function will be called and will probably look something like this:
function (newDoc, oldDoc) {
//How do I get this array to contain the emails of all the users?
var allEmail;
if (allEmail.indexOf(newDoc.email) !== -1) {
throw "This email adress is already taken";
}
};
How can I fill the array allEmail to contain all emails of the users?
Is it possible to call views in the validation function?
Not possible. Validation function only operates with updated doc and his previous revision and it cannot access to other documents. The only field that guaranteed to be unique is document _id. If it's possible and doesn't produce security/privacy issues, use email as doc _id to be ensure that it's unique.
Otherwise you have to create a view with target field as a key and check for it existence first before create a new doc on the client side. However, this logic easily becomes ruined when you'll replicate docs from other instance.
If the application is in offline, the above suggested solution how will react. Local pouch view can check and return the pouch results alone. There may be a high chance of same value entered from some other end and updated to couch db.
Do you have workaround for this case ?

Resources