Jump to content

jQuery multiselect sends wrong priority on insert with set_relation_n_n

multiselect set_relation_n_n priority

  • Please log in to reply
1 reply to this topic

#1 ricardomduarte



  • Members
  • PipPip
  • 11 posts

Posted 06 March 2013 - 04:39 PM



First of all, congratulations for the great piece of software that is GroceryCRUD. I love the architecture simplicity and flexibility.


I'm having the following problem:



I'm working on the form to add a musical project.


The "project" table has an n-to-n relationship with the "musician" table, materialized on the relationship table "musicianinproject". 


On grocery crud I use the following:


$crud->set_relation_n_n('musicians', 'musicianinproject', 'musician', 'project_id', 'musician_id', 'name', 'priority');


This is working well and if I have a priority manually defined on the database records the musician list is displayed correctly.



However, when I try to add a project via Grocery Crud, although I am able to select the musicians and order them on the multiselect interface, when I hit Save to submit the form, musicians array on the post array comes with the wrong order, and are thus written to the database with the wrong priority.



I read through the source code and investigated the issue and the most relevant information I got is on the post below, that relates to the same issue on the jQuery multiselect:





It seems that, since the source of the post data is a <select> element, there is no guarantee about the order of the selected options that will be sent by the browser.



If necessary I can post the code and logs on the server side showing the post data, but I will probably need to change the code to strip it of extra code irrelevant to this problem.



Thanks in advance for any help on this,


#2 davidoster


    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 07 March 2013 - 10:50 PM

I am not sure what exactly you are having as a result in your database.

Please have a look on this, http://eletter.gr/sa...film_management


This is the films' example that is included in the stable 1.3.3 version of Grocery CRUD library.

Try it out by adding and then editing the film you stored.

On the fields, Actors and Categories, which are defined via a set_relation_n_n, the order of submission is retained.


$crud = new grocery_CRUD();
		$crud->set_relation_n_n('actors', 'film_actor', 'actor', 'film_id', 'actor_id', '{fullname} {last_update}','priority');
		$crud->set_relation_n_n('category', 'film_category', 'category', 'film_id', 'category_id', 'name', 'priority');
		$crud->fields('title', 'description', 'actors' ,  'category' ,'release_year', 'rental_duration', 'rental_rate', 'length', 'replacement_cost', 'rating', 'special_features');
		$output = $crud->render();


I hope this is the issue you are referring to and this helps you out.



rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---



David Oster aka George Pasparakis,

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users