-
Notifications
You must be signed in to change notification settings - Fork 920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataTables ajax fails on 1-n relation #153
Comments
Ive already tried the method here: #87 (comment) P.S i just did composer update and the crud and base were updated along with laravel framework update but the issue still persists. |
Just to clarify something, You've got [
// 1-n relationship
'label' => "State", // Table column heading
'type' => "select",
'name' => 'state_id', // the method that defines the relationship in your Model
'entity' => 'state', // the method that defines the relationship in your Model
'attribute' => "name", // foreign key attribute that is shown to user
'model' => "App\Models\State", // foreign key model
], However, you only posted your Country model - I think yu should have a relationship inside your State model called "country" with another belongsTo in it // State.php
public function country()
{
return $this->belongsTo('App\Models\Country');
} then within your original addFields call change the I believe the way it works is, It looks for the method defined within name/entity, inside the model you pass in. As you're passing in the State model, its looking for |
Hi @mpixelz , I completely agree with @OwenMelbz - the 1-n column (select) works with 1-n relationships only. The relationship between your City and Country isn't 1-n. It's more like 1-n-n :-) I have only one thing to add to @OwenMelbz 's response, only if his solution doesn't work for you: I think you might be able to create a fake 1-n relationship between City and Country using Laravel's hasManyThrough(). However, I haven't tried that myself in Backpack. Cheers! PS. If you end up trying hasManyThrough(), I'm very eager to find out if it worked :-) |
@mpixelz just doing the cleaning, so closing the issue, feel free to re-open if you still need help! |
reopening this as the issue still persists.
in my crud.. when i use this model on select for 1-n relation:
now when i enable ajax tables i get the error.. but if i remove this column it works fine. |
Hi,
i have three relations (country, state, city) so 1 country with many states, 1 state with many cities..
when i have more than 1 belongsTo in my city model it does not fetch the connected country.. without ajax it times out max_execution time error.. but when i enable
$this->crud->enableAjaxTable();
it gives me:
DataTables warning: table id=crudTable - Ajax error. For more information about this error, please see http://datatables.net/tn/7
here is my CityCrudController:
here is my model City.php
how can i connect the country to the city model so it will display connected country through state relation?
The text was updated successfully, but these errors were encountered: