Comments (11)
Hey @rokcarl. Any chance you could show me your models on http://paste.laravel.com? I'm guessing this is an eloquent problem (i.e. you'll likely have to define the static $key property in your models) , and I could help you out if I saw what's going on.
from laravel-administrator.
Sure. There's quite a lot of code, so let me just shortly describe it: on the top you have my models config from administrator.php, then you have admin models and then the non-admin models.
We have a Country that has_many Company that has_many Document that belongs_to a DocumentType.
from laravel-administrator.
Hey @rokcarl, so the issue here is in your Eloquent model. Whenever you have underscores in a foreign field name, you typically have to explicitly declare what that field is. I've run into this sort of thing recently on a site I'm making where there are Properties, Property Types, Parts, Part Types, etc. So the solution is very simple. Basically in your DocumentType model, in the documents() relationship, you need to do this:
return $this->has_many("Document", 'document_type_id');
That will let Eloquent know what field to look for on the 'documents' table. I'm a little more confused about why it's looking for 'document_types.country' instead of 'document_types.country_id'. I think if you provide 'country_id' to the has_many relationship, it will work, though. Can you do me a favor and try to play around with these models outside the administrator context? Let me know if you see errors there too.
from laravel-administrator.
Sure, I'll do that, thanks for your help and I'll get back to you with the results.
from laravel-administrator.
Hmmm, I've looked into it and it seems like there's a problem in administrator? I don't know, you'll know ;).
I read your response. My previous error was when accessing /admin/documenttype within the class DocumentType. It has a function country
with return $this->belongs_to("Country");
, error was Unknown column 'document_types.country'
for SQL: SELECT document_types.id, document_types.type, document_types.country_id, document_types.country FROM document_types WHERE id = ? LIMIT 1
Then I changed this to return $this->belongs_to("Country", "asdf");
, just to see what I'd get. I got
Unknown column 'document_types.asdf'
for
SQL: SELECT document_types.id, document_types.type, document_types.asdf, document_types.country FROM document_types WHERE id = ? LIMIT 1
Then I changed it to return $this->belongs_to("Country", "country_id");
and I got again:
Unknown column 'document_types.country'
for
SQL: SELECT document_types.id, document_types.type, document_types.country_id, document_types.country FROM document_types WHERE id = ? LIMIT 1
This SQL doesn't look good to me and I think that administrator is creating this one? Or at least setting it up using Eloquent. This document_types.country is wrong. I think it should be a join or another query.
from laravel-administrator.
Hmm...it would appear you're right. What version of Administrator are you using?
from laravel-administrator.
I'm using 2.2. The funny thing is that I don't know how to download the 2.3 version. I've gone to the 2.3 branch (https://github.com/FrozenNode/Laravel-Administrator/tree/2.3.0) and can't see where I can download it. I've gone then to downloads, but these are for the current branch (2.2). Am I doing it wrong?
from laravel-administrator.
Oh weird I never knew you couldn't DL a branch as a zip. I think your best option is to fetch the branch via git.
from laravel-administrator.
Now I could download it :). So now with the 2.3 version, the issue remains. Have you looked into it yet?
from laravel-administrator.
Hmmm, I guess I f'ed up! My $edit variable in DocumentType had a 'country' array, which had
'relationship' => 'country'
instead of 'type' => 'relationship'
. Now works. I'll close the issue, investigate and then reopen if needed, but I think this is it.
from laravel-administrator.
@rokcarl awesome good to know! Thanks for reporting back here. To be honest, I had been waiting for the moment when that would confuse people. I think I'm eventually going to make the $column array have 'type' => 'relationship'
to avoid confusion. Will require a bit of reorganization though :)
from laravel-administrator.
Related Issues (20)
- how to upload mp3 file and get its duration in laravel 4.2 HOT 1
- add persian (farsi) language
- Domain HOT 3
- WYSIWYG: disable remove class
- Laravel 5.3 Mysql Strict Compatibly Issue HOT 2
- Frozennode.com HOT 10
- edit_fields in type "relationship" doesn't work when foreign key is a non-primary key.
- Response::download not work in global action HOT 1
- error "MethodNotAllowedHttpException in RouteCollection.php line 218:" on laravel 5.3
- Add field type "array"
- How to change column value depending on selection of other field using relationship field
- Trying to change the value of uri in administartor.php returns InvalidArgumentException in UrlGenerator.php line 307: Route [admin_dashboard] not defined. HOT 2
- documentation HOT 1
- Laravel 5.4 support HOT 6
- File Download Dialog does not trigger in Chrome 57 HOT 4
- Master / Child form
- Pulling out of this project HOT 1
- can't register provider in config/app.php
- ERROR: Function name must be a string
- PHP 7.2.4 sizeof(): Parameter must be an array or an object that implements Countable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-administrator.