Created
December 4, 2011 17:05
-
-
Save disbelief/1430700 to your computer and use it in GitHub Desktop.
dm-redis-adaptor has n, :through associations incomplete after reload
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
class User | |
include DataMapper::Resource | |
property :id, Serial | |
property :full_name, String, :length => 25, :required => true | |
property :email, String, :length => 320, :required => true | |
has n, :company_memberships | |
has n, :companies, :through => :company_memberships | |
end | |
class Company | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String, :required => true | |
has n, :company_memberships | |
has n, :users, :through => :company_memberships | |
end | |
class CompanyMembership | |
include DataMapper::Resource | |
belongs_to :user, :key => true | |
belongs_to :company, :key => true | |
end | |
# I call flushall on Redis before performing the following: | |
u = User.create :full_name => 'Joe Blow', :email => '[email protected]' | |
c = Company.create :name => 'Sprockets' | |
u.companies << c | |
u.save | |
#=> true | |
u.companies | |
#=> [#<Company @id=1 @name="Sprockets">] | |
u.company_memberships | |
#=> [#<CompanyMembership @user_id=1 @company_id=1>] | |
u1 = User.first | |
u1 == u | |
#=> true | |
u1.companies | |
#=> [#<Company @id=1 @name="Sprockets">] | |
u1.company_memberships | |
#=> [] | |
c1 = Company.first | |
c1 == c | |
#=> true | |
c1.users | |
#=> [#<User @id=1 @username="JoeBlow" @full_name="Joe Blow" @email="[email protected]">] | |
c1.company_memberships | |
#=> [] | |
CompanyMembership.all | |
#=> [#<CompanyMembership @id=nil @user_id=nil @company_id=nil>] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment