spec/fixtures/models.rb in dbee-1.2.1 vs spec/fixtures/models.rb in dbee-2.0.0.pre.alpha
- old
+ new
@@ -6,76 +6,59 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
module Models
- class Movies < Dbee::Base
- end
+ class Movie < Dbee::Base; end
- class PhoneNumbers < Dbee::Base
- end
+ class PhoneNumber < Dbee::Base; end
- class Demographics < Dbee::Base
- association :phone_numbers, model: 'Models::PhoneNumbers',
- constraints: {
- name: :demographic_id,
- parent: :id
- }
+ class Demographic < Dbee::Base
+ child :phone_numbers
end
- class MembersBase < Dbee::Base
- table 'members'
+ class MemberBase < Dbee::Base
+ child :demos, model: 'Models::Demographic', foreign_key: :member_id
- association :demos, model: Demographics,
- constraints: { type: :reference, name: :member_id, parent: :id }
-
- association :movies, model: Movies,
- constraints: { name: :member_id, parent: :id }
+ child :movies, foreign_key: :member_id
end
- class Members < MembersBase
- association :favorite_comic_movies, model: Movies, constraints: [
- { type: :reference, name: :member_id, parent: :id },
- { type: :static, name: :genre, value: 'comic' }
- ]
+ class Member < MemberBase
+ table 'members'
- association :favorite_mystery_movies, model: Movies, constraints: [
- { type: :reference, name: :member_id, parent: :id },
+ child :favorite_comic_movies, model: Movie, static: { name: :genre, value: 'comic' }
+
+ child :favorite_mystery_movies, model: Movie, constraints: [
{ type: :static, name: :genre, value: 'mystery' }
]
- association :favorite_comedy_movies, model: Movies, constraints: [
- { type: :reference, name: :member_id, parent: :id },
- { type: :static, name: :genre, value: 'comedy' }
- ]
+ child :favorite_comedy_movies, model: Movie, constraints: {
+ type: :static, name: :genre, value: 'comedy'
+ }
end
- class TheatersBase < Dbee::Base
- association :members, model: Members, constraints: [
- { type: :reference, name: :tid, parent: :id },
+ class TheaterBase < Dbee::Base
+ child :members, foreign_key: :tid, constraints: [
{ type: :reference, name: :partition, parent: :partition }
]
end
- class Theaters < TheatersBase
+ class Theater < TheaterBase
table 'theaters'
- association :parent_theater, model: self, constraints: [
- { type: :reference, name: :id, parent: :parent_theater_id }
- ]
+ parent :parent_theater, model: self
end
class A < Dbee::Base
table 'table_set_to_a'
end
class B < A
table 'table_set_to_b'
end
- class C < A
- end
+ class C < A; end
class D < A
table ''
end
@@ -83,40 +66,34 @@
table 'table_set_to_e'
end
end
module ReadmeDataModels
- class PhoneNumbers < Dbee::Base
+ class PhoneNumber < Dbee::Base
table :phones
end
- class Notes < Dbee::Base
- end
+ class Note < Dbee::Base; end
- class Patients < Dbee::Base
- association :notes, model: Notes, constraints: {
- type: :reference, name: :patient_id, parent: :id
+ class Patient < Dbee::Base
+ child :notes
+
+ child :work_phone_number, model: PhoneNumber, static: {
+ name: :phone_number_type, value: 'work'
}
- association :work_phone_number, model: PhoneNumbers, constraints: [
- { type: :reference, name: :patient_id, parent: :id },
- { type: :static, name: :phone_number_type, value: 'work' }
- ]
-
- association :cell_phone_number, model: PhoneNumbers, constraints: [
- { type: :reference, name: :patient_id, parent: :id },
+ child :cell_phone_number, model: PhoneNumber, constraints: [
{ type: :static, name: :phone_number_type, value: 'cell' }
]
- association :fax_phone_number, model: PhoneNumbers, constraints: [
- { type: :reference, name: :patient_id, parent: :id },
+ child :fax_phone_number, model: PhoneNumber, constraints: [
{ type: :static, name: :phone_number_type, value: 'fax' }
]
end
- class Practices < Dbee::Base
- association :patients, model: Patients, constraints: {
+ class Practice < Dbee::Base
+ association :patients, constraints: {
type: :reference, name: :practice_id, parent: :id
}
end
end
@@ -124,39 +101,38 @@
class BaseA < Dbee::Base
association :b1, model: 'Cycles::B'
end
class A < BaseA
+ table :as
+
association :b2, model: 'Cycles::B'
end
class B < Dbee::Base
- association :c, model: 'Cycles::C'
+ association :c
- association :d, model: 'Cycles::D'
+ association :d
end
class C < Dbee::Base
- association :a, model: 'Cycles::A'
+ association :a
end
class D < Dbee::Base
- association :a, model: 'Cycles::A'
+ association :a
end
end
# Examples of Rails Single Table Inheritance.
module PartitionerExamples
- class Owners < Dbee::Base
- association :dogs, model: 'PartitionerExamples::Dogs', constraints: {
- name: :owner_id, parent: :id
- }
+ class Owner < Dbee::Base
+ child :dogs
end
- class Animals < Dbee::Base
- end
+ class Animal < Dbee::Base; end
- class Dogs < Animals
+ class Dog < Animal
partitioner :type, 'Dog'
partitioner :deleted, false
end
end