Apostrophe Pieces joins with users

217 views Asked by At

I'm creating a schema that I'd like to have a relationship with apostrophe-users but can't seem to get it working?

{
      name: '_coaches',
      label: 'Coaches',
      type: 'joinByArray',
      withType: 'apostrophe-users' // also tried just 'user(s)',
      idsField: 'coachIds'
}

Does anyone know if the above is even possible and if so what I'm doing wrong?

Secondly, would it be possible to filter the above on whether they are in the 'coaches' group or not. So only users that are in a particular group are able to be selected for the above relationship.

1

There are 1 answers

1
Tom Boutell On BEST ANSWER

I am the lead developer of Apostrophe at P'unk Avenue.

This is working in a sense, however users are always unpublished by default with that field removed from the schema, so the public can never find them.

This is because in our experience, mixing the concept of a person in a front end directory of people and a user who can log in usually led to frustration and confusion in Apostrophe 0.5. "This is a user but they can't log in? This is an account but they don't belong in the directory? I don't get it," etc.

So we recommend making a separate "profile" piece type to represent a person on the front end, and allowing users and groups to be used for logins and permissions and nothing else.

It's possible to add the published field back to users and groups if you really want to via addFields but we don't recommend it.

Hmm but all that being said, the actual bug in your join is that you should have used apostrophe-user (see the name property in the apostrophe-users module; this is what one user is called, in the type property in the docs collection, which is different from the name of the module). Instances are singular, modules are plural. Depending on your intended application this could be what you needed to know.

As for joining only to people who are members of a particular group, I wonder why you don't instead join with that group and look at its _users join. You will need to set the join filter to explicitly fetch that additional join since Apostrophe does not recursively join by default to prevent infinite loops.