GithubHelp home page GithubHelp logo

Latest Release Breaks STI about retire HOT 8 CLOSED

aaronchi avatar aaronchi commented on September 15, 2024
Latest Release Breaks STI

from retire.

Comments (8)

karmi avatar karmi commented on September 15, 2024

Hmm, that is weird -- could you check if STI uses a _type method of the model? Previously, both type and _type methods were defined for the model instance in question.

from retire.

karmi avatar karmi commented on September 15, 2024

Any news on this?

from retire.

aaronchi avatar aaronchi commented on September 15, 2024

I don't believe STI uses _type but something happens when you include Tire::Model::Search that breaks the type handling. I'll take a deeper look sometime next week and see if I can figure out what's going on.

from retire.

aaronchi avatar aaronchi commented on September 15, 2024

Ah yes. I believe rails does use _type internally. there may be other stuff going on as well.

In my model:

class Image < Asset

end

without tire:

> Image.first._type
 ←[1m←[35mImage Load (1.0ms)←[0m  SELECT `assets`.* FROM `assets` WHERE `assets`.`type` IN ('Image') LIMIT 1
=> "Image"

with tire:

> Image.first._type
←[1m←[35mImage Load (1.0ms)←[0m  SELECT `assets`.* FROM `assets` WHERE `assets`.`type` IN ('Image') LIMIT 1
 NoMethodError: You have a nil object when you didn't expect it!
 You might have expected an instance of Array.
 The error occurred while evaluating nil.[]
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/tire-0.3.1/lib/tire/model/search.rb:199:in `block (2 levels) in <class:InstanceMethodsProxy>'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/tire-0.3.1/lib/tire/model/search.rb:259:in `_type'
    from (irb):66
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:35:in `require'
    from script/rails:35:in `<main>'

also:

> Image.first
  ←[1m←[36mImage Load (0.0ms)←[0m  ←[1mSELECT `assets`.* FROM `assets` WHERE `assets`.`type` IN ('Image') LIMIT 1←[0m
(Object doesn't support #inspect)
=>

from retire.

karmi avatar karmi commented on September 15, 2024

Hmm, _type should not be added when the model has that method already defined. Could you create a Rails template which generates some STI scaffolds etc, so I have less work with recreating that?

from retire.

karmi avatar karmi commented on September 15, 2024

Any news? Neither #type nor #_type really should be added to your model on 0.3.

from retire.

aaronchi avatar aaronchi commented on September 15, 2024

I added a basic rails app that shows the problem here:
https://github.com/aaronchi/tire-sti

Tire is defined on the Image model which is a child of the Asset model. If you go into console and try to create an image

Image.create(:title => 'Something')

You get the error I was describing above:

 NoMethodError: You have a nil object when you didn't expect it!
 You might have expected an instance of Array.
 The error occurred while evaluating nil.[]
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/tire-0.3.2/lib/tire/model/search.rb:199:in `block (2 levels) in <class:InstanceMethodsProxy>'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/tire-0.3.2/lib/tire/model/search.rb:259:in `_type'

If you move the tire index to the Asset model, creation works fine because it doesn't conflict with the STI type variable.

from retire.

karmi avatar karmi commented on September 15, 2024

OK, thanks for being stubborn on this. I have found the offending code and moved the the unneccessary methods into Model::Persistence. The sample app works now.

from retire.

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.