diff options
| author | mo khan <mo@mokhan.ca> | 2014-06-12 21:03:21 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-06-12 21:03:21 -0600 |
| commit | 7a3079c4c3821d3130524c81a18c66b044fc9115 (patch) | |
| tree | de8e33a5d21203fa70cd353821d17686540e812a | |
| parent | 56f17f9cf3035c11f07bb605884b18ee5e45dce1 (diff) | |
load a belongs to relationship
| -rw-r--r-- | lib/humble/column.rb | 6 | ||||
| -rw-r--r-- | spec/integration/select_spec.rb | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/humble/column.rb b/lib/humble/column.rb index 8320e84..0fa73b8 100644 --- a/lib/humble/column.rb +++ b/lib/humble/column.rb @@ -52,8 +52,10 @@ module Humble @type = type end - def apply(id, entity) - #entity.public_send("#{column_name}=", id) + def apply(value, entity) + child_entity = @type.new + column = column_name.to_s.gsub(/_id/, '') + entity.public_send("#{column}=", child_entity) end def prepare(entity) diff --git a/spec/integration/select_spec.rb b/spec/integration/select_spec.rb index 9a1c4ea..8b453b5 100644 --- a/spec/integration/select_spec.rb +++ b/spec/integration/select_spec.rb @@ -37,7 +37,7 @@ describe "select items" do expect(result).to be_instance_of(Movie) expect(result.id).to eql(movie_id) expect(result.name).to eql('blood in, blood out') - #expect(result.studio).to be_instance_of(Studio) + expect(result.studio).to be_instance_of(Studio) end end end |
