Hmm
Looking into it
Really appreciate it!
Though, if you got the
Not supportederror, it may be
Seems like it should be though
Yeah, I thought maybe I have the query syntax wrong for relationship fields, but then it wouldn't work for a single relationTo.
tried also
'field.ID': {contains: 1}and:
field: {
collection1: {
contains: 1,
}
},This is postgres?
yeah, postgres
I'm searching for your exact error message, so far I've founmd
throw new InvalidConfiguration(
'Unique is not supported in Postgres for hasMany text fields.',
)
throw new InvalidConfiguration(
'Unique is not supported in Postgres for hasMany number fields.',
)what is your exact message
ill try to match it with the codebase
Error: Not supportedinteresting
That's the payload error?
gives me 500 error
/admin/collections/clubs?limit=10Might be from here
https://github.com/payloadcms/payload/blob/61da01099144fcefee7bec98e631e8a964179b76/packages/db-postgres/src/queries/getTableColumnFromPath.ts#L529Doesn't seem right though
I'm using the query in a access function return.
Not sure if that matters, but wanted to mention it.
That's the only instance of that exact error message in the codebase from what I can see
Whats the access function look like
import type { Access } from 'payload'
export const accessTo: Access = ({ req }) => {
return {
created_for: {
contains: 1,
},
}
}{
admin: {
allowCreate: false,
// @TODO Enable this when not debugging
hidden: false,
},
hasMany: true,
label: 'Created For',
name: 'created_for',
relationTo: ['partners', 'clubs'],
required: true,
type: 'relationship',
index: true,
},This is the field
so I tested
relationTo: 'partners'and it worked.
hmm
I wonder if there is a workaround to get the data you need
Yeah that seems to be the error
Or where it gets thrown
yeah
We don't know which condition failed though
I have content that is going to created from different relations
- Partners
- Clubs
- Groups
So you could have a Partner create and Event or have a Club under a Partner create and Event etc.
My plan was to have a switcher set a cookie or a preference on the user and the access controls would filter based on the partner, club, group in the created_for field.
if that makes sense.
So you can switch between a partner, club, or group and the access would filter the content based on reference fields value.
it's fairly complex, but thought the query api would support a multi relationTo query.
It does seem odd that's not available
yeah
Though, you could tackle some of this logic. For instance, setting the user preference
why it makes me think my query syntax is wrong.
hmm
maybe it's just contains?
Would like..
equals work?
no, same error for equals
and how about
inin: [1, 2, 3]
same error
I'm just looking through the code where the throw happens to see if I can meet a condition maybe.
Doesn't look like it's supported tho.
hmm
Based on those conditions?
This is on v2 right?
no sorry v3
also seems that the throw is for 'upload' case in the drizzle package on beta branch.
sorry my bad it's for both
ok i created a v3 instance
So i created an Items collection
a Fruits collection
and a Vegetables collection
How should i setup to mirror what youre attempting
Create a created_for field on your items collection that has this
{
admin: {
allowCreate: false,
// @TODO Enable this when not debugging
hidden: false,
},
hasMany: true,
label: 'Created For',
name: 'created_for',
relationTo: ['fruits', 'vegetables'],
required: true,
type: 'relationship',
index: true,
},ok i did
then you can create a access function for the items collection
import type { Access } from 'payload'
export const accessTo: Access = ({ req }) => {
return {
created_for: {
contains: 1,
},
}
}create an item that at has a reference and then assign the access function and you should get the error when trying to view the list or single item.
like this
then enable access?
yeah
for read?
yeah, or all I don't think it maters.
Error: formattedValue.replace is not a function
odd
import type { CollectionConfig } from 'payload'
import { accessTo } from '../TestAccess'
export const Items: CollectionConfig = {
slug: 'items',
admin: {
useAsTitle: 'title',
},
access: {
read: accessTo,
},
fields: [
{ name: 'title', type: 'text' },
{
admin: {
allowCreate: false,
// @TODO Enable this when not debugging
hidden: false,
},
hasMany: true,
label: 'Created For',
name: 'created_for',
relationTo: ['fruits', 'vegetables'],
required: true,
type: 'relationship',
},
],
}whats your accessTo look like?
import type { Access } from 'payload'
export const accessTo: Access = ({ req }) => {
return {
created_for: {
contains: 1,
},
}
}looks fine.
its deff in the access fn
i changed it to return true and the error went away
yeah
I can do the same with my setup and then I don't get the Not Support error.
super odd you get a different error though
are you at beta.91 or higher?
I cancheck
I think i setup this v3 instance like 2-3 weeks ago
When i do this
export const accessTo: Access = ({ data, id }) => {
console.log(data, id)
return true
}I can see
{
title: 'Hello World',
updatedAt: '2024-08-28T15:05:06.687Z',
createdAt: '2024-08-28T15:05:06.687Z',
created_for: [
{ relationTo: 'fruits', value: '66cf3a89ec8261afd0393ad3' },
{ relationTo: 'vegetables', value: '66cf3a93ec8261afd0393b35' }
]
} would a length check on
data.created_fornot be the same?
I wasn’t getting anything back from data when I tried
Was undefined
Yeah, I could just do the check on data, but how would that work on lists?
Maybe the data is empty on a list view?
Hmm
Well im not sure why i get like a bunch of undefined then the value
Do you always get ID back
Only on a single view an id is available
Will double check
wait
Note: Field Access Controls does not support returning Query constraints like Collection Access Control does.Is the access supposed to limit document operations
or specific to the field
For document
The field is just so I know who has access to that document
Hmm
So you didn't want to use roles?
Like in your case fruits and vegetables are types of users?
it's a little more complicated from my side.
I have users but they can have multiple memberships to say Partners, Clubs and Groups.
then they would have roles for the membership they reside under if that make sense.
I see
I was wondering if the admin access rule could maybe help
access: {
admin: ({ req: { user }}) => {
return Boolean(user)
},
},which specifically restricts access to auth enabled collections
this just disables admin access and makes it api only right?
true
it's kinda like a multi-tenant app but with more than one tenancy if that make sense.
Partners, Clubs and Groups instead of just a single tenancy.
I might have to split the fields out into the different tenancies instead of having a single field I guess.
I can definitely brainstorm a bit
Sorry I couldnt be more helpful 😄
you've been more than helpful man.
it's just super complex system I'm trying to build and I'm not sure if Payload can support it maybe.
Always happy to help - I'll keep this open so someone else who may know more can add some info
sounds good man thanks!
I'm not the best with relational data stuff, but there are some folks here!
Solved it in the end and it was a syntax error like I thought.
So it should be like this:
{'field.value': { in: [1, 2, 3] }}Star
Discord
online
Get dedicated engineering support directly from the Payload team.