Struct type for uid predicate

I am struggling to find, what type of uid should be set for struct in golang.

I have follow predicate of uid type and in my Users struct, I have follow string type like below

type Users struct {
    Name string
    Email string
    Follow string
}

and my predicate is:-

Name: string @index(term) .
Email: string @index(exact) @upsert .
Follow: uid @count

Whenever, I am trying to create user without providing follow data.

It gives me an error:- “rpc error: code = Unknown desc = Input for predicate Follow of type uid is scalar

What struct type should I use for “Follow”. I have more uid type predicate.

I don’t know golang but the example here is specifying uid within the back tick json syntax.
As in,

Uid string `json:"uid,omitempty"`

See person struct

https://godoc.org/github.com/dgraph-io/dgo

1 Like

Thank you bro! This solved the issue but now, OwnerUserID is not storing data passed.

I just encountered another error with it, It now omits data completely and does not register the data :-

type Post struct {
	UID              string `json:"uid,omitempty"`
	CreatedAt        *time.Time
	Body             string
	Title            string
	OwnerUserID      string `json:"uid,omitempty"`
}

p := Post{
	CreatedAt:   &cdate,
	Body:        ask.Content,
	Title:       ask.Title,
	OwnerUserID: "0x2",
}

The recorded information after running below query is:-

me(func: uid($id)) {
	uid
	Title
	OwnerUserID
	Tags
}

You can see below output data, it completely omits “OwnerUserID” and has no data stored.

{"me":[
{"uid":"0xb",
"Title":"What should I do to improve my memory?",
"Tags":" story life meToo problem memory health"}
]
}

Rocky,
Did 0x2 exist in the database before you added the post object? If not, meaning you are adding bother owner and post in the same transaction then , I think you need to prefix your golang uids values with the _:

S

Yes, it already exists in the database. There is already user with uid 0x2. Infact, even if it does not exist, it should have at least stored the data, but it is not storing the data at all.

Here is query and result

{
   me(func: uid("0x2")) {
    uid
    Name
  }
}

Result :-

"data": {
    "me": [
      {
        "uid": "0x2",
        "Name": "Alice"
      }
    ]
  },