Skip to content
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

pagination errors #156

Open
carcinocron opened this issue Jan 29, 2020 · 1 comment
Open

pagination errors #156

carcinocron opened this issue Jan 29, 2020 · 1 comment

Comments

@carcinocron
Copy link
Contributor

I have a model which is very simple

class Model::Channel
  include Clear::Model
  self.table = "channels"

  column id : Int64, primary: true, presence: false
  column createdby_id : Int64

  column name : String
  column description : String

  column created_at : Time
  column updated_at : Time
end

# paginated query
channels = Model::Channel.query.paginate(1, 15)

after this code, I can't do anything with channels.

  puts channels.size

causes:

In src/app.cr:41:1

 41 | require "./routes"
      ^
Error: while requiring "./routes"


In src/routes.cr:10:1

 10 | require "./routes/channels"
      ^
Error: while requiring "./routes/channels"


In src/routes/channels.cr:12:17

 12 | puts channels.size
                    ^---
Error: instantiating 'Model::Channel::Collection#size()'


In /usr/share/crystal/src/enumerable.cr:1241:5

 1241 | count { true }
        ^----
Error: instantiating 'count()'


In /usr/share/crystal/src/enumerable.cr:243:30

 243 | each { |e| count += 1 if yield e }
                                ^
Error: can't use `yield` inside a proc literal or captured block

Make sure to read the whole docs section about blocks and procs,
including "Capturing blocks" and "Block forwarding":

http://crystal-lang.org/docs/syntax_and_semantics/blocks_and_procs.html

and

  channels.each do |c|
    puts c
  end

causes:

In src/app.cr:41:1

 41 | require "./routes"
      ^
Error: while requiring "./routes"


In src/routes.cr:10:1

 10 | require "./routes/channels"
      ^
Error: while requiring "./routes/channels"


In src/routes/channels.cr:14:12

 14 | channels.each do |c|
               ^---
Error: instantiating 'Model::Channel::Collection#each()'


In lib/clear/src/clear/model/collection.cr:307:40

 307 | o << Clear::Model::Factory.build(type, hash, persisted: true, fetch_columns: fetch_columns, cache: @cache).as(T)
                                  ^----
Error: instantiating 'Clear::Model::Factory:Module#build(String, Hash(String, Array(JSON::Any) | Array(PG::BoolArray) | Array(PG::CharArray) | Array(PG::Float32Array) | Array(PG::Float64Array) | Array(PG::Int16Array) | Array(PG::Int32Array) | Array(PG::Int64Array) | Array(PG::NumericArray) | Array(PG::StringArray) | Array(PG::TimeArray) | Bool | Char | Clear::Expression::UnsafeSql | Float32 | Float64 | Hash(String, JSON::Any) | Int16 | Int32 | Int64 | Int8 | JSON::Any | PG::Geo::Box | PG::Geo::Circle | PG::Geo::Line | PG::Geo::LineSegment | PG::Geo::Path | PG::Geo::Point | PG::Geo::Polygon | PG::Numeric | Slice(UInt8) | String | Time | UInt16 | UInt32 | UInt64 | UInt8 | Nil))'


There was a problem expanding macro '__register_factory__'

Called macro defined in lib/clear/src/clear/model/modules/has_factory.cr:30:3

 30 | macro __register_factory__

Which expanded to:

 > 1 |     
 > 2 |       __default_factory__
 > 3 |     
 > 4 |   
Error: expanding macro


There was a problem expanding macro '__default_factory__'

Called macro defined in lib/clear/src/clear/model/modules/has_factory.cr:23:3

 23 | macro __default_factory__

Which expanded to:

 > 1 |     Clear::Model::Factory.add("Model::Channel", ::Clear::Model::Factory::SimpleFactory(Model::Channel).new)
 > 2 |   
Error: undefined constant Model::Channel
@anykeyh
Copy link
Owner

anykeyh commented Feb 2, 2020

That's a problem I know exists and should be fixed.

Basically, you should use channels.count or channels.to_a.size

For explanation, I've made the collection object inheriting from enumerator class, which is probably not the best idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants