V8-archive: Creating item with relational O2M not able to create multiple, only 1 relational

Created on 2 Aug 2019  Â·  17Comments  Â·  Source: directus/v8-archive

Bug Report

Steps to Reproduce

  • Fresh install of v2.3.1
  • Create members collection with name text field
  • Create projects collection with name text field and members O2M relationship such that collection fields look like this:
    image

  • And the members O2M relation properties look like this:
    image

  • Now create TWO member items via project creation form
    image

  • Save the project item

  • Check the saved project item and you will see only 1 member item.

Expected Behavior

TWO members created should display

Actual Behavior

Only one member is displayed.

Other Context & Screenshots

You can contact me for the screenrecording

Technical Details

  • Device: Desktop
  • OS: Win 10 10.0.18362.145
  • Web Server: Apache/2.4.29
  • PHP Version: PHP 7.1.30
  • Database: 10.1.40
  • Install Method: v2.3.1 build
  • Directus App: 7.8.0
bug

Most helpful comment

Ask and ye shall receive! We're releasing in a few hours and you can no longer select the PK as "field_many" when setting up O2M relationships. 😄

All 17 comments

@JbalTero

  • And the members O2M relation properties look like this:
    image

When you have added O2M field in the collection then you must have M2O field in the related collection.

Here, You mapped id of projects collection with id of members collection which causes this issue. Kindly add M2O field in Members collection and map that field here.

You can get more detail from here.

Ohh ok I will try it thanks

This seems like a configuration issue, let us know if you still are having issues.

@bjgajjar it means I have to create the project first before the member? it is not possible to create project + create member?

@bjgajjar I added m2o in members collection like this:

image

Now when I add Project item, the Add new button doesn't make sense because it asks for Project selection which I am still yet to create.

And the problem is still the same. Watch here

What am I missing?

@JbalTero

You want to create O2M relation of member collection in project collection.

Kindly follow the below steps to add this relation in your collection.

  • Add M2O filed with name project_id in member collection which has a relation with project collection
  • Add O2M field in project collection which has a relation with member collection and map M2O filed project_id of member collection here.

@bjgajjar the steps above still yields the same issue, only 1 member is added even adding multiple. Like the screenrecording from above comment

@JbalTero

Can you please check that your project collection has a projects field as a relational field?

image

@bjgajjar It is set to id

image

BTW I'm using App version: 7.8.0

@JbalTero

That's the cause of issue.

Kindly set the M2O field over there.

@JbalTero THANK YOU! it works now

This pretty much comes back round to the app again and (PEBKAC): Can we disable the option of being able to select the primary key as a relation here? @directus/app-team

Right during creation of the relation, id is pre-selected and cannot be modified. Not until it is updated.

Yes @shealavington — that would solve a lot of these issues and _should_ be pretty easy to do. I'll look into doing it (😬) but no promises!

@rijkvanzanten you agree with this approach?

Yup!

Ask and ye shall receive! We're releasing in a few hours and you can no longer select the PK as "field_many" when setting up O2M relationships. 😄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cdwmhcc picture cdwmhcc  Â·  3Comments

cdwmhcc picture cdwmhcc  Â·  3Comments

Nitwel picture Nitwel  Â·  3Comments

HashemKhalifa picture HashemKhalifa  Â·  3Comments

jwkellyiii picture jwkellyiii  Â·  3Comments