setRelationNtoN can't use $crud->fields?

I finally managed to get setRelationNtoN to work by changing the names of some of the fields (I usually use a scheme like film_fk to distinguish it from film_id in the main database but that doesn’t work with GroceryCRUD, it turns out).

But now that I have it working there’s another issue I have run into. When adding/editing I don’t want to show all fields in the database and I also want to change the default order of the fields that I do want.

But this seems to be impossible because when using $crud->fields and trying to put in one of the new setRelationNtoN fields it stops the modal from even being loaded.

The example page also shows all fields in the database when editing, as far as I can tell.

Is there anyway to select and order just a limited number of fields? I truly hope so, otherwise this just won’t work for me.

Edit: just in case it matters, I am using version 2.7.4. (As it turned out I should have tried to download the newest version on the day before my purchase lapsed, not the day itself…)

I would really like to get an official answer on this.

Hello @Laurvin and welcome to our forums :hugs:

Can you please give us a code example of what it is not working for you? Keep in mind that the change ordering functionality for relation n to n is not working as the jquery plugin that we used for v1 is not actively developed anymore.

In the future I will try to have this functionality back but for now this is still not in the priority list for the next months (sorry)

Regards
Johnny

This is what I have:

$crud->setRelationNtoN('categories', 'film_category', 'category', 'film_id', 'category_id', 'name');
$crud->columns(['title', 'question', 'answer']);
$crud->defaultOrdering('film_id', 'desc');
$crud->setTexteditor(['question', 'answer']);

When I use $crud->fields it’s not possible to have the category show up and a few of the other fields in the main database.

I can select between a few of the fields in the main database but it’s impossible to have the category show up and a few other fields from the main database.

I am using 2.7.4., that’s not v1, is it?

First super quick test with the latest version of Grocery CRUD (thanks!) gives me the same result as before, the edit modal doesn’t even load.

Maybe I am missing something so let me ask it this way: looking at the example on the setRelationNtoN page, what would you have to do to make only the Title, Description, and Categories fields show up when clicking Edit on that page?

It would be just some form of $crud->fields, right?

Hello @Laurvin ,

I’ve tried it many times and I can’t reproduce the issue that you have unfortunetly. I’ve tried the below lines:

$crud->setRelationNtoN('actors','film_actor','actor','film_id','actor_id','{fullname} ({last_update})');
$crud->setRelationNtoN('categories', 'film_category', 'category', 'film_id', 'category_id', 'name');
$crud->fields(['title', 'categories', 'description']);

but everything is working as expected. Can you please give me more information of how to reproduce the issue? It doesn’t make much sense for me for the fields to break your CRUD but can you try to use the fields specifics for add/edit? For example instead of using the fields try to use: editFields instead.

Regards
Johnny

I found it, boy is my face red…

Turns out it was a stupid copy/paste error; I used ‘category’ instead of ‘categories’. I should really have gone for more descriptive names so this wouldn’t have happened.

I’m sorry for wasting your time!

1 Like