Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

MetaWhere breaks creating new objects from scopes #13

Closed
manuelmeurer opened this issue Apr 13, 2011 · 6 comments
Closed

MetaWhere breaks creating new objects from scopes #13

manuelmeurer opened this issue Apr 13, 2011 · 6 comments

Comments

@manuelmeurer
Copy link

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
Copy link

ernie commented Apr 13, 2011

It shouldn't. In fact, there are passing tests to check for this. Can you please contribute a failing test, after verifying you are in fact using the latest released gem?

See https://github.com/ernie/meta_where/blob/master/test/test_relations.rb#L61

On Apr 13, 2011, at 2:16 PM, manuelmeurer wrote:

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>

Reply to this email directly or view it on GitHub:
#13

@manuelmeurer
Copy link
Author

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 pushed a commit that referenced this issue Apr 13, 2011
@ernie
Copy link

ernie commented Apr 13, 2011

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
Copy link
Author

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
Copy link

ernie commented Apr 13, 2011

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
Copy link
Author

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

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

No branches or pull requests

2 participants