Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

MetaWhere breaks creating new objects from scopes #13

Closed
manuelmeurer opened this Issue · 6 comments

2 participants

@manuelmeurer

MetaWhere seems to break creating new objects from scopes:

class Foo < ActiveRecord::Base
  scope :bar, where(:baz => 'pelle')
end

# Without MetaWhere

Foo.bar.build
=> #<Foo id: nil, baz: "pelle">

# With MetaWhere

Foo.bar.build
=> #<Foo id: nil, baz: nil>
@ernie
Owner
@manuelmeurer

I tried to write a failing test but they all pass in the MetaWhere project.

Still, in my app (Rails 3.0.6, Ruby 1.9.2) it fails and MetaWhere is definitely the deciding factor.
The sample code I gave above is wrong, though, that case works as expected.
It fails when I try to initialize a new object through an association, like this:

class Oof < ActiveRecord::Base
  has_many :foos
end

class Foo < ActiveRecord::Base
  belongs_to :oof

  scope :bar, where(:baz => 'pelle')
end

# Without MetaWhere

Oof.new.foos.bar.build
=> #<Foo id: nil, baz: "pelle">

# With MetaWhere

Oof.new.foos.bar.build
=> #<Foo id: nil, baz: nil>

Any idea what the reason could be?

@ernie ernie referenced this issue from a commit
@ernie ernie Add a test for #13. af28154
@ernie
Owner

Not sure what to say. This test I just added is as close to a duplicate of your reported issue as I can come up with :(

@manuelmeurer

Yeah, that was exactly what I tried as well but the damn thing passes without a scratch. :)

Oh well, I'll try to figure it out.
If I find the solution, I'll let you know!

Thanks for your great work with MetaWhere!

@ernie
Owner

One last comment -- you don't happen to have a default_scope on the models in question, do you? I've seen those cause some strange issues in the past... :/

@manuelmeurer

Nope, no default_scope. Those things have bitten me more than once as well, so I stopped using them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.