Skip to content

Instantly share code, notes, and snippets.

@jc00ke
Created November 6, 2011 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jc00ke/1342585 to your computer and use it in GitHub Desktop.
Save jc00ke/1342585 to your computer and use it in GitHub Desktop.
# Imagine that Play & Author were stored in their own collections
# hanging off of Maglev.PERSISTENT_ROOT
class Play
attr_accessor :title
end
class Author
attr_accessor :name
def initialize
@plays = []
end
def plays
@plays
end
def add_play(play)
@plays << play
end
end
Maglev.abort_transaction
bill = Author.new
bil.title = "William Shakespeare"
rnj = Play.new
rnj.title = "Romeo & Juliet"
bill.add_play(rnj)
Maglev.commit_transaction
Maglev.abort_transaction
assert("Romeo & Juliet", Author.first.plays.first.title)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment