Create a gist now

Instantly share code, notes, and snippets.

@mtitolo /Models.rb Secret
Created May 1, 2016

What would you like to do?
class User
include DataMapper::Resource
# property <name>, <type>
property :id, Serial
property :name, String
property :email, String
has n, :group_memberships
has n, :memberships, model: 'Group', child_key: [:id], parent_key: [:user_id], through: :group_membership
end
class Group
include DataMapper::Resource
# property <name>, <type>
property :id, Serial
property :name, String
property :created_at, DateTime
has n, :group_memberships
has n, :members, model: 'User', child_key: [:id], parent_key: [:group_id], through: :group_membership
end
class GroupMembership
include DataMapper::Resource
# property <name>, <type>
property :id, Serial
property :status, Enum[:pending, :accepted, :declined], default: :pending
property :roles, Enum[:owner, :member], default: :member
property :created_at, DateTime
property :user_id, Integer
property :group_id, Integer
belongs_to :membership, model: 'User', child_key: [:user_id]
belongs_to :member, model: 'Group', child_key: [:group_id]
end
$ rake db:create
rake aborted!
NoMethodError: undefined method `name' for nil:NilClass
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/associations/many_to_many.rb:267:in `block in one_to_many_options'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/subject_set.rb:211:in `block in each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `block in each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/subject_set.rb:211:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/associations/many_to_many.rb:267:in `map'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/associations/many_to_many.rb:267:in `one_to_many_options'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-constraints-1.2.0/lib/data_mapper/constraints/relationship/many_to_many.rb:11:in `one_to_many_options'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/associations/many_to_many.rb:67:in `block in through'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core.rb:263:in `block in repository'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/repository.rb:114:in `scope'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core.rb:263:in `repository'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/associations/many_to_many.rb:66:in `through'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/associations/many_to_many.rb:131:in `finalize'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:783:in `block in finalize_relationships'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/subject_set.rb:211:in `block in each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `block in each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/subject_set.rb:211:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:783:in `finalize_relationships'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/model.rb:137:in `finalize'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core.rb:281:in `block in finalize'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/descendant_set.rb:64:in `block in each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/subject_set.rb:211:in `block in each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `block in each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/ordered_set.rb:320:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/subject_set.rb:211:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core/support/descendant_set.rb:63:in `each'
/Users/michele/.rvm/gems/ruby-2.3.0/gems/dm-core-1.2.1/lib/dm-core.rb:281:in `finalize'
/Users/michele/Projects/picsnearme-web/padrino-test/picsnearme/config/boot.rb:47:in `block in <top (required)>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment