graffiti-mongoose icon indicating copy to clipboard operation
graffiti-mongoose copied to clipboard

Query by reference

Open ovaris opened this issue 9 years ago • 2 comments

Hi, newbie question here, how can I query by model reference? I would like to query all Topic-models of certain Forum, my models (simplified):

var Topic = new Schema({
        uuid: {
            type: String,
            index: true,
            unique: true
        },
        title: {
            type: String
        },
        forum: {
            type: ObjectId,
            ref: "Forum",
            index: true
        },
})

var Forum = new Schema({
   title: {
            type: String,
            required: true
        }
});

I would like to

query TopicsByForum{
  topics(forum:"nnn"){
    forum{title}
  }
}

ovaris avatar Mar 17 '16 12:03 ovaris

I made a PR for this issue https://github.com/RisingStack/graffiti-mongoose/pull/112

choyongjoon avatar Apr 15 '16 02:04 choyongjoon

Dont think this is relay supported. Why would you have topics as a parent of forum anyways?

Makes more sense if it is like this:

query ForumTopics{
  forum(title:"nnn"){
    topics{
      uuid
      title
    }
  }
}

st0ffern avatar Sep 07 '16 09:09 st0ffern