Backbone-relationalでBackboneを使用しています。私は2つのモデルを持っています、Appointment
そしてClient
、ここで、Client
は多くを持つことができますAppointments
。これが私のClient
モデル定義です(CoffeeScriptで):
class Snip.Models.Client extends Backbone.RelationalModel
paramRoot: 'client'
relations: [
type: Backbone.HasMany
key: 'appointments'
relatedModel: 'Snip.Models.Appointment'
collectionType: 'Snip.Collections.AppointmentsCollection'
reverseRelation:
type: Backbone.HasOne
key: 'client'
includeInJSON: 'id'
]
defaults:
name: null
phone: null
email: null
notes: null
active: null
class Snip.Collections.ClientsCollection extends Backbone.Collection
model: Snip.Models.Client
url: '/clients'
そして、これが私のAppointment
モデル定義です:
class Snip.Models.Appointment extends Backbone.RelationalModel
paramRoot: 'appointment'
defaults:
time_block_type_code: 'APPOINTMENT'
start_time: null
stylist: null
salon: null
client: Snip.Models.Client() # This doens't work
class Snip.Collections.AppointmentsCollection extends Backbone.Collection
model: Snip.Models.Appointment
url: '/appointments'
問題は次のとおりです。Client
参照しているので、ファイルの前にファイルAppointment
を含める必要があります。そうすれば、参照するまでにクラスが存在します。ただし、参照もあるので、キャッチ22のような状況です。どうしたらいいのかわからない。Appointment
Client
Snip.Models.Appointment
Appointment
Client