Query for a node, filtering using uid of child nodes (relations) - dgraph

If have a schema "Like" that has relations to User Schema (user_id) and Post Schema (object_id). How can I query for the "Like" nodes that have user_id = (some_uid) and object_id = (some_uid).
I am using dgraph-io/dgraph-js.
User Schema Post Schema Like Schema
uid uid uid
first_name type object_id (maps post)
last_name content user_id (maps user)
email title
created_at

Try this
{
likes(func: has(like.object_id)) #filter(uid_in(like.object_id, 0x2) and uid_in(like.user_id, 0x3)){
like.object_id {
uid
post.type
post.content
post.title
}
like.user_id{
uid
user.email
user.first_name
user.last_name
}
}
}

Related

how to fetch mapped columns in prisma2

I am new to prisma2 and I have created the below model schema with #map annotation
model User {
id Int #id #default(autoincrement())
name String #map("user_name")
}
Now when i see in my db I am having two columns in User table id and user_name but when i am fetching the data from user table like below:
const users = prisma.users.findMany()
So i am getting data like
[
{
id:1,
name: null
}
]
Because the schema points to name where as name is mapped to user_name, please help me how can i fetch the db column user_name in the result alias as name
output should be like below:
[
{
id:1,
user_name: "name value"
}
]
#map Maps a field name or enum value from the Prisma schema to a column or document field with a different name in the database.
So in your database the name of the column will be user_name but in the generated client the name of the field will be name.
#map does change the field names in the generated client.
If you want to use user_name in the response you will need to define it as user_name in your schema file.
model User {
id Int #id #default(autoincrement())
user_name String
}
#map reference

Getting Empty array when FQL querying the event_member table with uid condition

When I execute the following FQL query
SELECT uid, rsvp_status FROM event_member WHERE uid = me()
I get a list of events I'm attending. When I execute either of the following FQL querys
SELECT uid, rsvp_status FROM event_member WHERE uid = "{my uid written out}"
SELECT uid, rsvp_status FROM event_member WHERE uid IN ("{my uid written out}")
I get the following empty object
{"data": []}
I want to query for my friends public events using. When I trying to do this using either of the following queries
SELECT uid, rsvp_status FROM event_member WHERE uid = "{my friends uid written out}"
SELECT uid, rsvp_status FROM event_member WHERE uid IN ("{my friends uid written out}")
I once again get the following empty object
{"data": []}
Any suggestions?

FQL Filter user Table By name

It says in the FQL user Documentation that there are 4 indexable fields (marked with *):
name
third_party_id
uid
username
But when I perform a query like this:
SELECT uid
FROM user
WHERE name = "Mark Zuckerberg"
I get an error:
{
"error": {
"message": "Your statement is not indexable. The WHERE clause must contain
an indexable column. Such columns are marked with * in the
tables linked from
http://developers.facebook.com/docs/reference/fql ",
"type": "NoIndexFunctionException",
"code": 604
}
}
What am I missing here? Is this a bug? How can I filter an FQL query on the user table by name?
Awaiting response from FB on this bug, but meanwhile there is a workaround.
The indexable column name works in the profile table and can return its id field, which corresponds to the uid column in the user table, e.g.
SELECT first_name FROM user WHERE uid IN (SELECT id FROM profile WHERE name="Mark Zuckerberg")

How to Add table association in Entity Framework?

I have a table called User, a table called Permission and an association table so Many Users can have many Permissions.
User
ID - PK
Permission
ID - PK
UserPermission
UserID - PK (FK to user)
PermissionID - PK (FK to Permission)
In entity framework how can I add an entry to the association table to link a user to a permission?
I have tried the following with no luck:
var user = _Repository.Users.Single(u => u.ID == someUserID);
var permission = _Repository.Permissions.Single(p => p.ID == somePermissionID);
user.Permissions.Add(permission) //Not working
user.Permission.Attach(permission) //Still not working
_Repository.Save();
Can anyone help?
It should be :
UserPermission obj = new UserPermission { UserID = someUserID, PermissionID = somePermissionID };
_Repository.UserPermissions.AddObject(obj)
_Repository.Save();
Hope this will help.

Get user name of comment in comments table FQL

I am getting Facebook comments data for particular posts using FQL. FQL returns only fromid however i need fromname as well. I am using batch request for getting comments of 50 posts at same time.
My query is
SELECT object_id,post_id,fromid,time,text,id,reply_xid,post_fbid,is_private FROM comment WHERE post_id='".$postID."'
How can I do this?
you need to make an additional query, something like this:
$multiQuery_postInfo = array(
"posts" => "SELECT post_id, actor_id, message, message_tags, likes, comments, share_count, attachment, action_links, type FROM stream WHERE source_id=$pageID",
"users" => "SELECT uid, username, first_name, last_name, profile_url, pic FROM user WHERE uid IN (SELECT actor_id FROM %23posts)"
);