Created
September 27, 2010 15:22
-
-
Save clarkware/599206 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
# | |
# Quick hack to map an iOS app's Core Data managed SQLite database into ActiveRecord | |
# | |
class CoreDataBase < ActiveRecord::Base | |
self.abstract_class = true | |
set_primary_key "Z_PK" | |
# Map all ZXXX attributes to XXX | |
def method_missing(method, *args) | |
column_name = "Z#{method.to_s.upcase}" | |
respond_to?(column_name) ? send(column_name, *args) : super | |
end | |
end | |
class Event < CoreDataBase | |
set_table_name "ZEVENT" | |
belongs_to :track, :foreign_key => "ZTRACK" | |
has_many :sessions, :foreign_key => "ZEVENT" | |
end | |
class Track < CoreDataBase | |
set_table_name "ZTRACK" | |
has_many :events, :foreign_key => "ZTRACK" | |
end | |
class Session < CoreDataBase | |
set_table_name "ZSESSION" | |
belongs_to :event, :foreign_key => "ZEVENT" | |
has_many :laps, :foreign_key => "ZSESSION" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment