apostrophecms / apostrophecms/apostrophe

And or other builders not working in relationship field schema ?

Open
#4,892 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
4.6k
Forks
650
Avg merge
19h 21m
Merged PRs (30d)
23

Description

PLEASE NOTE: make sure the bug exists in the latest patch level of the project. For instance, if you are running a 2.x version of Apostrophe, you should use the latest in that major version to confirm the bug.

## To Reproduce

Step by step instructions to reproduce the behavior:

> 1. Add a moule with relationship field and builder defined. An index.js provided '...'
> 2. index.js `export default {
extend: "article",
options: {
label: "Frame",
pluralLabel: 'Frames',
shortcut: 'Shift+Alt+F'
// Additionally add a `pluralLabel` option if needed.
},
fields: {
add: {
frame: {
htmlHelp:
"Unique Frame Id. Distinct from ”:NAME”, ”name”, ”...name” or ”...id” slots",
type: "string",
required: true,
},
frame_type: {
label: "Select a frame type",
type: "select",
choices: [
{
label: "Simple Instance",
value: 5,
},
{
label: "Class",
value: 6,
},
{
label: "Slot",
value: 7,
},
{
label: "Facet",
value: 8,
},
],
required: true,
},
values: {
label: "Slot and Facet Values",
type: "array",
titleField: "values",
inline: true,
fields: {
add: {
_slot: {
type: "relationship",
withType: "frame",
max: 1,
min: 1,
req: true,
builders: {
// Include only the information you need with a projection
frame_type: '7',
},
},
_facet: {
type: "relationship",
withType: "frame",
max: 1,
builders: {
// Include only the information you need with a projection
and: { frame_type: { $eq: 8 } },
},
},
is_template: {
type: "boolean",
required: true,
def: false,
},
value_index: {
type: "integer",
required: true,
def: 0,
},
value_type: {
label: "Select a value type",
type: "select",
choices: [
{
label: "Integer",
value: 1,
},
{
label: "Float",
value: 2,
},
{
label: "String",
value: 3,
},
{
label: "Boolean",
value: 4,
},
{
label: "Simple Instance",
value: 5,
},
{
label: "Class",
value: 6,
},
{
label: "Slot",
value: 7,
},
{
label: "Facet",
value: 8,
},
],
required: true,
},
value_integer: {
label: "Value",
type: "integer",
if: {
value_type: 1,
},
},
value_float: {
label: "Value",
type: "float",
if: {
value_type: 2,
},
},
value_string: {
label: "Value",
type: "string",
if: {
value_type: 3,
},
},
value_boolean: {
label: "Value",
type: "boolean",
if: {
value_type: 4,
},
},
_value_simple_instance: {
label: "Value",
type: "relationship",
withType: "frame",
max: 1,
builders: {
// Include only the information you need with a projection
and: { frame_type: 5 },
},
if: {
value_type: 5,
},
},
_value_class: {
label: "Value",
type: "relationship",
withType: "frame",
max: 1,
builders: {
// Include only the information you need with a projection
and: { frame_type: { $eq: 6 } },
},
if: {
value_type: 6,
},
},
_value_slot: {
label: "Value",
type: "relationship",
withType: "frame",
max: 1,
builders: {
// Include only the information you need with a projection
and: { frame_type: { $eq: 7 } },
},
if: {
value_type: 7,
},
},
_value_facet: {
label: "Value",
type: "relationship",
withType: "frame",
max: 1,
builders: {
// Include only the information you need with a projection
and: { frame_type: { $eq: 8 } },
},
if: {
value_type: 8,
},
},
},
},
},
},
group: {
frame: {
label: 'Frame',
fields: ["frame", "frame_type", "values"],
},
content: {
label: 'Content',
fields: ['_heroImage', 'excerpt', 'mainContent']
},
basics: {
label: 'Basic Info',
fields: ['_author', 'category', 'publishDate', '_related']
}
},
},
filters: {
add: {
frame: {
label: "Frame",
},
frame_type: {
label: "Frame Type",
},
},
},
columns: {
add: {
frame: {
label: "Frame",
},
frame_type: {
label: "Frame Type",
},
category: {

}
},
},
};
`
> 3. Populate instances with frame_type = 5,6,7, 8
> 4. Add values
> 5. Add related slot. Suggested frames should be restricted to instances with with frame_type = 7. Instead all instances suggested although the frame_type

## Expected behavior
> A clear and concise description of what you expected to happen.

Limited set of suggested instances conform the builder criteria (and) other than the project builder.

## Describe the bug
> A clear and concise description of what the bug is.
Hi,
May I use **and builder** or one other than **project** like in the following snippet ?
I am trying to limit the suggested items in the admin UI to those with frame_type field (select) value = 7 .

` ...
_slot: {
type: "relationship",
withType: "frame-1",
max: 1,
min: 1,
req: true,
builders: {
//Suggest Only items with the frame_type = 7
//frame_type defined with a select field type
//frame_type: '7', ?
//frame_type: 7, ?
//and: { frame_type: { $eq: '7' } }, ?
and: { frame_type: { $eq: 7 } },
},
}, ...
`

Not working for me now.

## Details

**Version of Node.js:**
*PLEASE NOTE: Only stable LTS versions (10.x and 12.x) are fully supported but we will do our best with newer versions.*

v20.5.1
"apostrophe": "^4.12.0",
Apollo

**Server Operating System:**
*The server (which might be your dev laptop) on which Apostrophe is running. Linux? MacOS X? Windows? Is Docker involved?*

MacOS 15.3.2

**Additional context:**
> Add any other context about the problem here. If the problem is specific to a browser, OS or mobile device, specify which.

**Screenshots**
*If applicable, add screenshots to help explain your problem.*

![Image](https://github.com/user-attachments/assets/0e7dc7b7-a508-4372-9b9c-e0e018454fe9)
![Image](https://github.com/user-attachments/assets/7d6b0181-b52e-44e4-b99f-560bc6a6448d)

Contributor guide

Open the contributing guide

Research direction

Start with the relationship field schema and builders shown in the supplied index.js, then reproduce the admin suggestions using frame_type values 5–8. Check how the and builder is applied to relationship fields and verify that suggestions are limited to frame_type 7 rather than all frame instances.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.