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
@loader Issues #258
Comments
This error can happen if you have both a public and a private class Example. The error is a bit misleading. Not sure this is the case, though, you'd have to check if there's a private class Example somewhere in amber that is somehow being used... |
I think @asterite is right, this is due to there being a duplicate name in the class namespace somewhere. I don't think Granite has any class called Example, and on #244 the error was more specific and certainly didn't include anything that is part of Granite. @J-Mo63 the query syntax in #244 is not documented because it's not solidified and not available for use with mysql and sqlite yet. As a result, it's only available my manually importing the DSL into a model. Thanks for stopping by @asterite |
Hmm, it doesn't seem to be a conflict in my class naming however I could be wrong so this is the repo for reference. After doing a find all in my project files (and not coming up with any other results), purging my the new model module Frost
class Abcd < Granite::Base
extend Granite::Query::BuilderMethods
adapter pg
# Fields
timestamps
primary id : Int64
field name : String
field body : String
# Object methods
end
end table creation # Migrate DB
initialise_tables [Frost::User, Frost::Abcd] calling action def index
Frost::Abcd.create(name: "Test", body: "Data")
respond Frost::Abcd.all
end the current error instantiating 'ExampleApi#index()'
in src/api/example_api.cr:6: instantiating 'Frost::Abcd:Class#all()'
respond Frost::Abcd.all
^~~
in lib/granite/src/granite/querying.cr:52: instantiating 'all(String, Array(Bool | Float32 | Float64 | Int32 | Int64 | Slice(UInt8) | String | Time | Nil))'
def all(clause = "", params = [] of DB::Any)
^
in lib/granite/src/granite/querying.cr:53: instantiating 'Granite::Collection(Frost::Abcd):Class#new(Proc(Array(Frost::Abcd)))'
Collection(self).new(->{ raw_all(clause, params) })
^~~
in lib/granite/src/granite/collection.cr:4: instance variable '@loader' of Granite::Collection(Frost::Abcd) must be Proc(Array(Frost::Abcd)), not Proc(Array(Frost::Abcd))
def initialize(@loader : -> Array(M))
^~~~~~~ |
I did some trial and error and seemed to narrow it down to something in the I'll see if i can figure anything out. Edit: Seems it narrows down further to |
@Blacksmoke16 how did you narrow it down to the |
Could just be coincidence, but removing 🤷♂️ |
Urgh, what a pain. I may end up switching routers if I can't figure this one out. Thank you for your input! |
I'd checkout https://github.com/amberframework/amber-router |
I'd check if there are aliases in mime-types. There are some bugs related to alias types that might cause this problem. |
For example: class Session; end
alias CmdHandler = Array(Session)
CmdHandler.class
class Foo
def initialize(@h : CmdHandler)
end
end
class SmtpSession < Session
end
Foo.new([] of Session) Gives:
It's basically crystal-lang/crystal#1346 , which I'll fix tomorrow. |
(though it might happens with non-aliases, not sure, you'd have to reduce the codebase to find out...) |
Wow, so you fixed this for non-top-level Any other major situation that can cause the |
It seems so :-P You'll have to reduce the code to find out. |
So after demolishing all of Orion and Mime-Type's code, I got it working, but still couldn't pinpoint a single fix for it that I could push up to their repos. So in defeat, I moved some days ago to Toro, and it honestly suited my purposes better anyway (tree-oriented routing). While I have learned many a thing about the language from this debacle, this is clearly not a Granite problem, so I'm going to close the issue. Thanks for the very useful help and suggestions @asterite @Blacksmoke16 and @robacarp! |
Issue
I'm working on building out an API for myself and I'm currently trying to add persistence, however I get the following error from even a simple
Example.all
.I looked over issue #244 the other day in search of answers and the workaround provided isn't quite enough for my purposes (plus it looks a little hacky). There seems to be no documentation for the syntax described in the issue, and all I really want to do here is to call
.all
,.find
,.create
, and.update
. I don't have many dependencies for it to be clashing with unlike the other poster, and I'm not trying to do anything all that complex at this point.So my question:
Additional Code for Reference
shards.lock
all my requirements
calling my helper
model helper
my user model
my example model
the api method calling it
the full error (up to relevant trace)
The text was updated successfully, but these errors were encountered: