setRelation and callbackColumn

I have a setRelation like this:

$this->crud->setRelation( ‘ingrediente_id’, ‘ingredienti’, ‘{nome} ({um})’ );

This is perfect in the modal insert the dropdown show the nome and um as desired.

But the same appears in the column view where I need to show just name, I tried setting a callbackColumn but anything I try to do except than returning the value make thanother callbackColumn on another field to crash. I get an error 500

Any idea?

Fast and then we detail when you get a result.

Bad English, I use google translator

		$state_info = $crud->getStateInfo();
		$operation = $crud->getState();
				if( $operation == 'add' || $operation == 'insert' || $operation == 'insert_validation') {
		$this->crud->setRelation( ‘ingrediente_id’, ‘ingredienti’, ‘{nome} ({um})’ );
				} elseif ( $operation == 'edit' || $operation == 'update' || $operation == 'update_validation')	{
		$this->crud->setRelation( ‘ingrediente_id’, ‘ingredienti’, ‘{nome} ({um})’ );
				} else {
		$this->crud->setRelation( ‘ingrediente_id’, ‘ingredienti’, ‘{nome}’ );
				}

It doesn’t work, it always pass the if else till last one, if I dd($operation), I got ‘main’ that is a state not listed in documentation. I’m using insert and other operation in ajax. I’m under Laravel

Lik i didn’t have long searched on googl before posting here? LOL If I post here it’s cause I didn’t find an answer I suppose there should be some bug, so cause my company is paying the Enterprise version I supposed to ask here to get answer form expert even if not the developers,. Not a “Google for it” answer :slight_smile:

Hello @SteveAgl and welcome to our forums :slight_smile:

First of all the previous comment was probably a spam (e.g. not a real person posted it) but for now as I am not very sure, I’ve just flagged the answer so don’t worry too much about ironic comments for now :slight_smile:

Now for your initial question, the answer is a bit more complicated but I will try to make it as easy as possible. As summary what you are trying to do is not possible out of the box currently (to take the setRelation string and manipulate it with callbackColumn). Let me explain.

setRelation is basically changing the type of your field to “relation” so trying to change the field type to a callback it doesn’t do the change that you wish for. To simply say it, when you are trying to do a callbackColumn to the setRelation you take the id as an output and not the full string to manipulate it.

A quick solution that I can think for your problem is the below:

To use the fieldTypeColumn function that is based on the fieldType but it will also require a query to your database from laravel.

So the solution that we are looking for is this:

$crud->fieldTypeColumn('ingrediente_id', 'dropdown_search', [
    '52' => 'salt',
    '64' => 'sugar',
    ....
]);

Of course replace the hardcoded array with the ids should come from your database with a custom query model from your database that you will get the above output.

I hope the above helped.

Regards
Johnny