DB Not Updated When Using Options
DB Not Updated When Using Options
Hi,
I have been able to use the code below with no problems, ie. reading and writing to db and displaying data in Editor. But when I did a further refinement of the data as shown in the examples it no longer updates the DB, but the data is displayed in the Editor as desired. The only field that is not updated in the DB is the one with the added options to it.
I thank you in advance for any help.
Example from Manual:
Field::inst( 'users.site' )
->options( 'sites', 'id', 'name', function ($q) {
$q->where( 'name', 'L%', 'LIKE' );
} );
My Code:
public function classes_process($post)
{
Editor::inst($this->editorDb, $this->table_name, 'id')
->fields(
Field::inst('courses.title')
->validator('Validate::notEmpty'),
Field::inst($this->table_name . '.course_id')
->options('courses', 'id', 'title'),
Field::inst('users.last_name')
->validator('Validate::notEmpty'),
Field::inst($this->table_name . '.teacher_id')
** ->options('users', 'level', 'last_name', function ($q) {
$q->where('level', '%t%', 'LIKE');
}),**
Field::inst('cohorts.cohort_name'),
Field::inst($this->table_name . '.cohort_id')
->options('cohorts', 'id', 'cohort_name')
)
->leftJoin('courses', 'courses.id', '=', $this->table_name . '.course_id')
->leftJoin('users', 'users.id', '=', $this->table_name . '.teacher_id')
->leftJoin('cohorts', 'cohorts.id', '=', $this->table_name . '.cohort_id')
->process($_POST)
->json();
}
This question has an accepted answers - jump to answer
Answers
Is it the
course_id
orteacher_id
field which isn't woking? Or both?Are you able to give me a link to the page so I can take a look and see what is going wrong please?
Thanks,
Allan
Hi,
Thanks for the reply, it is the teacher_id that is not working correctly. The code without options just shows all of my users. The code with the options shows only the teachers as wanted. But the DB is not updated with the teacher_id on Edit or New.
Here is the JS code for the editor.
And this is the code for processing the AJAX data
I have tried several methods with little (no) success.
Thank you
That's very odd indeed! If you select a teacher for the full list, does that save to the database?
I'll try to create an example here and debug it locally.
Allan
Yes it does. All works perfectly, just have to deal with selecting the correct teacher out of a couple hundred users.
Thanks for helping
I think I got it to work
I have been testing it and it updates with just teacher view.
Just teacher being displayed I mean.
All I did was changed the 'level' in options for 'id' instead. Works like a charm.
Thanks for looking in to it. Is great tool set, the trick is to use it correctly.
Thanks
Bo
Hi Bo,
Thanks for posting back. Great to hear you've got it working now!
Regards,
Allan