Sha256: b15fbbfc95e12d1e2d01ef512cba928e8a9705dd314c9e20405e04f472419aad

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# -*- coding: utf-8 -*-

require 'rubygems'
require 'dm-core'
require 'dm-timestamps'
require 'extlib'

Extlib::Inflection.plural_word 'film', 'filmy' 
Extlib::Inflection.plural_word 'recenzja', 'recenzje'
Extlib::Inflection.plural_word 'kino', 'kina'

Extlib::Inflection.plural_word 'sesja', 'sesje'
# bug:
#  jeśli nazwa modelu kończy się na 's', to
#  datamapper głupieje, np.:
# Extlib::Inflection.plural_word 'seans', 'seanse'

DataMapper.setup :default, 'sqlite3:ale-kino.sqlite3'

log = DataMapper::Logger.new(STDOUT, :debug)

#log.push "==== hello datamapper"

class Film
  include DataMapper::Resource
  property :id,             Serial
  property :name,           String
  property :minutes,        Integer
  property :average_stars,  Float  
  timestamps :at

  has n, :recenzja
  has n, :sesja
  has n, :kino, :through => :sesja
end

class Recenzja
  include DataMapper::Resource
  property :id,           Serial
  property :author_name,  String
  property :stars,        Integer
  property :content,      Text  
  timestamps :at

  belongs_to :film
end

class Kino
  include DataMapper::Resource
  property :id,    Serial
  property :name,  String
  timestamps :at

  has n, :sesja
  has n, :film, :through => :sesja
end

class Sesja
  include DataMapper::Resource
  property :id,         Serial
  property :starts_on,  Date
  property :ends_on,    Date  
  timestamps :at
  
  belongs_to :kino
  belongs_to :film
end

DataMapper.auto_migrate!

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nosql-tutorial-0.1.1 lib/public/doc/datamapper/001-ale-kino.rb