Fixing association bug to avoid searching when foreign key is nil
This commit is contained in:
parent
226fe3bf38
commit
b81d37fc02
|
@ -109,7 +109,7 @@ module CouchRest
|
||||||
base = options[:proxy] || options[:class_name]
|
base = options[:proxy] || options[:class_name]
|
||||||
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
class_eval <<-EOS, __FILE__, __LINE__ + 1
|
||||||
def #{attrib}
|
def #{attrib}
|
||||||
@#{attrib} ||= #{base}.get(self.#{options[:foreign_key]})
|
@#{attrib} ||= #{options[:foreign_key]}.nil? ? nil : #{base}.get(self.#{options[:foreign_key]})
|
||||||
end
|
end
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,6 +62,12 @@ describe "Assocations" do
|
||||||
@invoice.client_id.should be_nil
|
@invoice.client_id.should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should not try to search for association if foreign_key is nil" do
|
||||||
|
@invoice.client_id = nil
|
||||||
|
Client.should_not_receive(:get)
|
||||||
|
@invoice.client
|
||||||
|
end
|
||||||
|
|
||||||
it "should raise error if class name does not exist" do
|
it "should raise error if class name does not exist" do
|
||||||
lambda {
|
lambda {
|
||||||
class TestBadAssoc < CouchRest::Model::Base
|
class TestBadAssoc < CouchRest::Model::Base
|
||||||
|
|
Loading…
Reference in a new issue