Skip to content

Use Plugin Multiple Times Per Schema #44

Description

@amerryma

Hi, I've been using this plugin for a long time now but I have an interesting use-case that I'm trying to solve without actually forking this library. Basically, we already use the plugin to add a tenantId to every mongoose model in our application, but we want to take it one step further. I wanted to add another field to the same model where I could chain the accessorMethod's and continue to narrow down the search. For example:

User

{
   name: "Aaron",
   tenantId: "A",
   tenantId2: "1"
}
{
   name: "Alrik",
   tenantId: "A",
   tenantId2: "2"
}
{
   name: "Someone",
   tenantId: "B",
   tenantId2: "2"
}

Basically as it stands right now I have to use User.byTenant("A") to get the model that I need for querying. But what I'd like to be able to do is something like User.byTenant("A").byTenant2("1") which would just return the Aaron user. I know it's not a typical use-case but just wondered if there would be an easy way to implement this. Otherwise if I end up forking it, do you have any recommendations?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions