Skip to content

Commit

Permalink
Lazy collection model
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Naiman committed Sep 30, 2016
1 parent 1505169 commit a69b68a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/rasti/db/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ def primary_key
end

def model
@model ||= Consty.get(demodulize(singularize(name)), self)
if @model.is_a? Class
@model
elsif @model
@model = Consty.get @model, self
else
@model = Consty.get demodulize(singularize(name)), self
end
end

def relations
Expand Down
8 changes: 8 additions & 0 deletions spec/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
collection_class.primary_key.must_equal :code
end

it 'Lazy model name' do
collection_class = Class.new(Rasti::DB::Collection) do
set_model :User
end

collection_class.model.must_equal User
end

end

describe 'Insert, Update and Delete' do
Expand Down

0 comments on commit a69b68a

Please sign in to comment.