V8-archive: Issue with M2M relationships

Created on 23 Sep 2019  路  8Comments  路  Source: directus/v8-archive

Bug Report

Steps to Reproduce

  1. In the App create 2 tables that you want to link with M2M relationship
  2. Add the M2M field to one of those tables by using Many-to-Many interface. Use automatic generation of Junction Table.
  3. Under 'options' tab in Many-to-Many interface form toggle on 'Allow Select' trigger
  4. Save the field and ensure that Junction Table is created
  5. Create one item in collection without M2M field
  6. Now go to create item in collection with M2M field. When you will click on 'Select Existing' button related to this M2M field, you will see that popup window not showing any data in the list, though it should show the one that was entered in the previous step.

Expected Behavior

The popup window should list one item in the list

Actual Behavior

No items displayed in the list

Other Context & Screenshots


Hi guys, I'm trying to implement m2m relationship but for some reason selecting items (browse) is not working - empty list is shown. When I've checked the API call that suppose to bring a list of items for selection I see the following error. I'm using the latest build version of API and App
UPDATE 1:
After brief investigation I've found that at the moment when createMetadataPagination method is called the $_GET is empty. Probably it caused by request query string that in my case was:limit=200&offset=0&meta=%2A&fields%5B0%5D=name&fields%5B1%5D=id&sort=name. Can it be that 'meta' query string param escaped by mistake?
UPDATE 2:
I've made a fix in line 1025 of RelationalTableGateway.php - I've added validation for case if $params['meta'] is undefined, and at least list is shown right now, though search is not working. But I'm not sure that fix should be done on API side...
So this is a new code:
$meta_param=explode(',',array_key_exists('meta', $params) ? $params['meta'] : "");
Instead of this one:
$meta_param=explode(',',$params['meta']);

image

Technical Details

  • Device: Desktop
  • OS: Windows 10.1803 & Ubuntu 16.04.1 WLS
  • Web Server: NGINX
  • PHP Version: 7.3.8
  • Database: MySQL 5.7.27
  • Install Method: cloned 'build' branch
bug alt stack

Most helpful comment

Hi @bjgajjar , thank you for reviewing this. I just have a small comment - if you've decided to replace $_GET with this code, you probably have to replace it also in createEntriesMetadata() method as well. Those are only 2 places where $_GET used in this class.

All 8 comments

@yarick2000 - I am not able to reproduce this error in neither local env nor live demo.

limit=200&offset=0&meta=%2A&fields%5B0%5D=name&fields%5B1%5D=id&sort=name

If this is the case then the meta param is already passed in the request[*]. Thus the undefined index is maybe not possible.

The screen recording will be really helpful for this case. As the issue is not reproducible based on the described steps.

@bjgajjar , here is a screen recording:
bug

image

I think this is a problem - in Slim $_GET params are not available: https://stackoverflow.com/questions/8125064/slim-php-and-get-parameters

I think this $_GET should be replaced with this: $this::$container->get('request')->getQueryParams() (or getParams()), but not sure 100%. Though when I did this replacement things started to work as they should

in Slim $_GET params are not available

Hey @yarick2000 - Sorry but I disagree with you here. $_GET is a PHP variable which must available in all PHP frameworks. Slim is one of them. So it should work over there.

In fact, I tried to replicate it in the live demo too. But not able to replicate it. Can you please try to upgrade your system?

Though I am sending PR with replace the $_GET with

$this::$container->get('request')->getQueryParams()

for a code improvement.

But I think the latest version must resolve your issue.
As well as you can find your solution in https://github.com/directus/api/pull/1313 :)

Hi @bjgajjar , thank you for reviewing this. I just have a small comment - if you've decided to replace $_GET with this code, you probably have to replace it also in createEntriesMetadata() method as well. Those are only 2 places where $_GET used in this class.

@yarick2000 - You can find it here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gitlabisbetterthangithub picture gitlabisbetterthangithub  路  3Comments

metalmarco picture metalmarco  路  3Comments

andgar2010 picture andgar2010  路  3Comments

rijkvanzanten picture rijkvanzanten  路  3Comments

HashemKhalifa picture HashemKhalifa  路  3Comments