Created
November 17, 2012 09:33
-
-
Save moonglum/4094497 to your computer and use it in GitHub Desktop.
A small example for Arrays in Ashikawa::AR
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 "ashikawa-ar" | |
Ashikawa::AR.setup :default, "127.0.0.1:8529" | |
class MyFineModel | |
include Ashikawa::AR::Model | |
attribute :name | |
# This is where the magic happens! | |
attribute :my_strings, Array[String] | |
end | |
# Let's delete the old versions. I want this to run multiple times! | |
MyFineModel.all.each { |a| a.delete } | |
# Create a new MyFineModel with an Array | |
a = MyFineModel.new name: "Nice name", my_strings: ["a", "b"] | |
p a.my_strings | |
a.my_strings << "c" | |
p a.my_strings | |
# Save it to the database | |
a.save | |
# Find it again. Just to show that it works when you read it | |
# back from the database :) | |
b = MyFineModel.first_example name: "Nice name" | |
p b.my_strings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment