Last active
December 13, 2015 16:39
-
-
Save jonnolen/4942031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'data_mapper' | |
require 'dm-timestamps' | |
require 'active_support/core_ext' | |
DataMapper::Model.raise_on_save_failure = true | |
class User | |
include DataMapper::Resource | |
property :id, String, :default => lambda {|r,p| SecureRandom.uuid}, :key=>true | |
property :givenName, String, :length => 255, :default => "" | |
property :surname, String, :length => 255, :default => "" | |
property :isTestUser, Boolean, :default => false | |
has n, :organizations | |
has n, :profiles | |
def default_profile | |
profiles.all(:organization => nil).first | |
end | |
end | |
class Profile | |
include DataMapper::Resource | |
property :id, Serial | |
belongs_to :organization, :required => false | |
belongs_to :user | |
has n, :fields # if i remove this line then Profile.all doesn't puke, if I have this line then any call to Profile.all fails with stack overflow. | |
end | |
class Field | |
include DataMapper::Resource | |
property :id, Serial | |
property :fieldType, String, :length => 200, :required => true | |
property :valueType, String, :length => 200, :required => true | |
property :value, String, :length => 500, :required => true | |
belongs_to :profile | |
end | |
class Organization | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
timestamps :at | |
belongs_to :user, :required=>false | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.create | |
user.profiles << Profiles.new | |
user.save | |
Profile.all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment