Add some files.
This commit is contained in:
parent
3f6ed4128c
commit
c2524fc675
3 changed files with 86 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
/.bundle/
|
/.bundle/
|
||||||
|
vendor/bundle
|
||||||
/.yardoc
|
/.yardoc
|
||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
/_yardoc/
|
/_yardoc/
|
||||||
|
|
62
example.activerecord
Normal file
62
example.activerecord
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
require 'active_record'
|
||||||
|
|
||||||
|
ActiveRecord::Base.logger = Logger.new(STDERR)
|
||||||
|
ActiveRecord::Base.colorize_logging = false
|
||||||
|
|
||||||
|
ActiveRecord::Base.establish_connection(
|
||||||
|
:adapter => "sqlite3",
|
||||||
|
:dbfile => ":memory:"
|
||||||
|
)
|
||||||
|
|
||||||
|
ActiveRecord::Schema.define do
|
||||||
|
create_table :albums do |table|
|
||||||
|
table.column :title, :string
|
||||||
|
table.column :performer, :string
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :tracks do |table|
|
||||||
|
table.column :album_id, :integer
|
||||||
|
table.column :track_number, :integer
|
||||||
|
table.column :title, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Album < ActiveRecord::Base
|
||||||
|
has_many :tracks
|
||||||
|
end
|
||||||
|
|
||||||
|
class Track < ActiveRecord::Base
|
||||||
|
belongs_to :album
|
||||||
|
end
|
||||||
|
|
||||||
|
album = Album.create(:title => 'Black and Blue',
|
||||||
|
:performer => 'The Rolling Stones')
|
||||||
|
album.tracks.create(:track_number => 1, :title => 'Hot Stuff')
|
||||||
|
album.tracks.create(:track_number => 2, :title => 'Hand Of Fate')
|
||||||
|
album.tracks.create(:track_number => 3, :title => 'Cherry Oh Baby ')
|
||||||
|
album.tracks.create(:track_number => 4, :title => 'Memory Motel ')
|
||||||
|
album.tracks.create(:track_number => 5, :title => 'Hey Negrita')
|
||||||
|
album.tracks.create(:track_number => 6, :title => 'Fool To Cry')
|
||||||
|
album.tracks.create(:track_number => 7, :title => 'Crazy Mama')
|
||||||
|
album.tracks.create(:track_number => 8,
|
||||||
|
:title => 'Melody (Inspiration By Billy Preston)')
|
||||||
|
|
||||||
|
album = Album.create(:title => 'Sticky Fingers',
|
||||||
|
:performer => 'The Rolling Stones')
|
||||||
|
album.tracks.create(:track_number => 1, :title => 'Brown Sugar')
|
||||||
|
album.tracks.create(:track_number => 2, :title => 'Sway')
|
||||||
|
album.tracks.create(:track_number => 3, :title => 'Wild Horses')
|
||||||
|
album.tracks.create(:track_number => 4,
|
||||||
|
:title => 'Can\'t You Hear Me Knocking')
|
||||||
|
album.tracks.create(:track_number => 5, :title => 'You Gotta Move')
|
||||||
|
album.tracks.create(:track_number => 6, :title => 'Bitch')
|
||||||
|
album.tracks.create(:track_number => 7, :title => 'I Got The Blues')
|
||||||
|
album.tracks.create(:track_number => 8, :title => 'Sister Morphine')
|
||||||
|
album.tracks.create(:track_number => 9, :title => 'Dead Flowers')
|
||||||
|
album.tracks.create(:track_number => 10, :title => 'Moonlight Mile')
|
||||||
|
|
||||||
|
puts Album.find(1).tracks.length
|
||||||
|
puts Album.find(2).tracks.length
|
||||||
|
|
||||||
|
puts Album.find_by_title('Sticky Fingers').title
|
||||||
|
puts Track.find_by_title('Fool To Cry').album_id
|
23
lib/timecost/environment.rb
Normal file
23
lib/timecost/environment.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
require 'active_record'
|
||||||
|
|
||||||
|
ActiveRecord::Base.logger = Logger.new(STDERR)
|
||||||
|
ActiveRecord::Base.colorize_logging = false
|
||||||
|
|
||||||
|
ActiveRecord::Base.establish_connection(
|
||||||
|
:adapter => "sqlite3",
|
||||||
|
:dbfile => ":memory:"
|
||||||
|
)
|
||||||
|
|
||||||
|
ActiveRecord::Schema.define do
|
||||||
|
create_table :albums do |table|
|
||||||
|
table.column :title, :string
|
||||||
|
table.column :performer, :string
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table :tracks do |table|
|
||||||
|
table.column :album_id, :integer
|
||||||
|
table.column :track_number, :integer
|
||||||
|
table.column :title, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue