Skip to content

Commit

Permalink
Merge pull request mongodb#3054 from dianaclarke/issue-3053
Browse files Browse the repository at this point in the history
allow read_attribute to work with an aliased field name
  • Loading branch information
durran committed May 17, 2013
2 parents f09c970 + 126d5a5 commit 8c4794f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoid/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def has_attribute_before_type_cast?(name)
#
# @since 1.0.0
def read_attribute(name)
normalized = name.to_s
normalized = database_field_name(name.to_s)
if hash_dot_syntax?(normalized)
attributes.__nested__(normalized)
else
Expand Down
15 changes: 15 additions & 0 deletions spec/mongoid/attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,21 @@
end
end
end

context "when attribute has an aliased name" do

let(:person) do
Person.new
end

before(:each) do
person.write_attribute(:t, "aliased field to test")
end

it "returns the value of the aliased field" do
expect(person.read_attribute(:test)).to eq("aliased field to test")
end
end
end

describe "#read_attribute_before_type_cast" do
Expand Down

0 comments on commit 8c4794f

Please sign in to comment.