axiom icon indicating copy to clipboard operation
axiom copied to clipboard

Move Limit#one to Relation#one

Open dkubb opened this issue 10 years ago • 2 comments

Allow #one to be called on unsorted relations

[Fix #60]

dkubb avatar Jul 17 '14 04:07 dkubb

@snusnu does this work like you expected it?

dkubb avatar Jul 17 '14 04:07 dkubb

@dkubb To make it work like before, I had to do the following to axiom-do-adapter.

+ b/lib/axiom/relation/gateway.rb
@@ -9,7 +9,7 @@ module Axiom
       DECORATED_CLASS = superclass

       # remove methods so they can be proxied
-      undef_method(*DECORATED_CLASS.public_instance_methods(false).map(&:to_s) - %w[materialize])
+      undef_method(*DECORATED_CLASS.public_instance_methods(false).map(&:to_s) - %w[materialize one])
       undef_method(:project, :remove, :extend, :rename, :restrict, :sort_by, :reverse, :drop, :take)

       # The adapter the gateway will use to fetch results

Failing to do so would lead to no SQL being executed when invoking #one, resulting in an error like the following:

  1) Ramom provides access to base relations
     Failure/Error: let(:account) { db.one(:accounts) }
     Axiom::NoTuplesError:
       one tuple expected, but was an empty set
     # .../axiom/lib/axiom/relation.rb:177:in `one'
     # .../axiom-do-adapter/lib/axiom/relation/gateway.rb:270:in `public_send'
     # .../axiom-do-adapter/lib/axiom/relation/gateway.rb:270:in `forward'
     # .../axiom-do-adapter/lib/axiom/relation/gateway.rb:244:in `method_missing'
     # ./lib/ramom/reader.rb:43:in `one'
     # ./lib/ramom/reader.rb:83:in `one'
     # ./spec/integration/schema_spec.rb:186:in `block (2 levels) in <top (required)>'
     # ./spec/integration/schema_spec.rb:191:in `block (2 levels) in <top (required)>'

snusnu avatar Jul 21 '14 14:07 snusnu