From a2f80c4e02c12b938f1658af162948a72950e44a Mon Sep 17 00:00:00 2001 From: Damien Date: Fri, 25 Mar 2016 18:37:14 -0700 Subject: [PATCH] Relationship queries: easier to scope/chain --- motion/cdq/relationship_query.rb | 4 +++- spec/cdq/relationship_query_spec.rb | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/motion/cdq/relationship_query.rb b/motion/cdq/relationship_query.rb index 5ba7cf0..a9f8424 100644 --- a/motion/cdq/relationship_query.rb +++ b/motion/cdq/relationship_query.rb @@ -3,6 +3,8 @@ module CDQ class CDQRelationshipQuery < CDQTargetedQuery + attr_reader :target_class + def initialize(owner, name, set = nil, opts = {}) @owner = owner ? WeakRef.new(owner) : nil @relationship_name = name @@ -132,7 +134,7 @@ def respond_to?(method) end def method_missing(method, *args, &block) - if @__query__.respond_to?(method) + if @__query__.target_class.respond_to?(method) || @__query__.respond_to?(method) @__query__.send(method, *args, &block) else super diff --git a/spec/cdq/relationship_query_spec.rb b/spec/cdq/relationship_query_spec.rb index 8c02313..87aed5b 100644 --- a/spec/cdq/relationship_query_spec.rb +++ b/spec/cdq/relationship_query_spec.rb @@ -53,6 +53,7 @@ class << self it "should be able to use named scopes" do cdq(@author).articles.all_published.array.should == [@article1, @article2, @article3] + @author.articles.all_published.array.should == [@article1, @article2, @article3] end it "can handle many-to-many correctly" do