Skip to content

Commit

Permalink
Added collection_fields to Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoneira committed Nov 29, 2019
1 parent c3d5b96 commit db299fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rasti/db/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def collection_name
@collection_name ||= underscore(demodulize(name)).to_sym
end

def collection_fields
@collection_fields ||= model.attributes - relations.keys
end

def primary_key
@primary_key ||= :id
end
Expand Down
2 changes: 2 additions & 0 deletions spec/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

it 'Implicit' do
Users.collection_name.must_equal :users
Users.collection_fields.must_equal [:id, :name]
Users.model.must_equal User
Users.primary_key.must_equal :id
Users.foreign_key.must_equal :user_id
end

it 'Explicit' do
People.collection_name.must_equal :people
People.collection_fields.must_equal [:document_number, :first_name, :last_name, :birth_date, :user_id]
People.model.must_equal Person
People.primary_key.must_equal :document_number
People.foreign_key.must_equal :document_number
Expand Down

0 comments on commit db299fe

Please sign in to comment.