GithubHelp home page GithubHelp logo

Comments (11)

janhartigan avatar janhartigan commented on June 2, 2024

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.

rokcarl avatar rokcarl commented on June 2, 2024

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.

http://paste.laravel.com/cVV

from laravel-administrator.

janhartigan avatar janhartigan commented on June 2, 2024

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.

rokcarl avatar rokcarl commented on June 2, 2024

Sure, I'll do that, thanks for your help and I'll get back to you with the results.

from laravel-administrator.

rokcarl avatar rokcarl commented on June 2, 2024

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.

janhartigan avatar janhartigan commented on June 2, 2024

Hmm...it would appear you're right. What version of Administrator are you using?

from laravel-administrator.

rokcarl avatar rokcarl commented on June 2, 2024

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.

janhartigan avatar janhartigan commented on June 2, 2024

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.

rokcarl avatar rokcarl commented on June 2, 2024

Now I could download it :). So now with the 2.3 version, the issue remains. Have you looked into it yet?

from laravel-administrator.

rokcarl avatar rokcarl commented on June 2, 2024

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.

janhartigan avatar janhartigan commented on June 2, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.