Comments (7)
The way relations are created changed quite a bit to follow rails 7.1 trends.
So a bug like there (where it is probably not delegating correctly) makes sense.
Using an active record 6.1 model, this is the functionality I get:
irb(main):001:0> VmOrTemplate.all.spawn.class
=> VmOrTemplate::ActiveRecord_Relation
irb(main):002:0> VmOrTemplate.all.class
=> VmOrTemplate::ActiveRecord_Relation
irb(main):003:0> VmOrTemplate.where(:id => 1).class
=> VmOrTemplate::ActiveRecord_Relation
Are you seeing similar behavior for your active hash model?
If you throw map onto all 3 of the above, do they work for you?
I'm swamped on work right now. Anyone else able to take a peek at this?
from active_hash.
@kbrock if somebody can point me in the right direction, I can take a stab at figuring it out.
from active_hash.
I'm investigating now!
from active_hash.
Ok, the problem here is that the attribute :display
collides with Object#display
.
Specifically, ActiveHash::Relation::Condition
uses public_send
to send a message by the name of the constraint key, and checks the result against the constraint value:
constraints.send(expectation_method) do |attribute, expected|
value = record.public_send(attribute)
matches_value?(value, expected)
end
For both objects, the value is nil
(so neither matches the display: true
constraint) and the response is an empty array, []
.
Unfortunately, Object#display
has a side effect of emitting information to STDOUT which makes the display garbled. If the output is this:
#<Disposition:0x00000001418dd4b0>#<Disposition:0x00000001418dcab0>#<Disposition:0x00000001418dc5b0>#<Disposition:0x00000001418d7ec0>#<Disposition:0x00000001418d7858>#<Disposition:0x00000001418d71c8>#<Disposition:0x00000001418d6c50>=> []
that's actually seven Disposition
objects having #display
called on them, followed by the irb prompt =>
followed by the actual result, []
.
So that's the diagnosis, anyway. Not sure about solutions right now.
from active_hash.
Here's a failing test that I'm working off of:
describe "colliding methods" do
it "should handle attributes named after existing methods" do
klass = Class.new(ActiveHash::Base) do
self.data = [
{
id: 1,
name: "Aaa",
display: true,
},
{
id: 2,
name: "Bbb",
display: false,
},
]
end
expect(klass.where(display: true).length).to eq(1)
end
end
from active_hash.
I started to try to make ActiveHash::Base
subclass BasicObject
but it's turning into quite an invasive change. Other creative ideas would be welcome, I think.
from active_hash.
I've submitted a PR at #281, which is a simple fix -- I'd love feedback on whether that's sufficient (or whether it will break untested use cases).
from active_hash.
Related Issues (20)
- Release master for Ruby 3 compatibility HOT 16
- Is it time to redefine the purpose of ActiveHash? HOT 9
- ActiveRecordExtensions.belongs_to with extra arguments is not working HOT 3
- Using ActiveHash::Associations and JSONAPISerializer at the same time will result NoMethodError. HOT 1
- Can a class that inherits from ActiveHash::Base be associated with another class that inherits from ActiveHash::Base? HOT 1
- The has_many :through Association does not get record HOT 6
- QUESTION: What's the performance of "find_by"? HOT 2
- Scopes are not chainable HOT 1
- Rails 7 finding a valid model association. HOT 6
- Rails 7 Compatibility HOT 4
- Make releases more often? HOT 3
- ActiveHash scope affecting self HOT 3
- Reflection Inheritance Issue HOT 4
- No Method Error for find_by and find HOT 1
- `ActiveHash::Relation` returned by `ActiveHash#where` should be reported like as an array of `ActiveHash` items selected by `where` method, in Rails Console. HOT 3
- ActiveHash::Relation can not use respond_to? method HOT 3
- find_by with nil value will return an object with an empty string
- undefined method `find_by_key' for ActiveYamlBaseClass:Class Did you mean? find_by_id HOT 3
- Accessing belongs_to association without a key creates a useless query HOT 4
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 active_hash.