Skip to content

Commit

Permalink
Rename 'jsonmodel_hint' to 'def_nested_record'
Browse files Browse the repository at this point in the history
  • Loading branch information
marktriggs committed Dec 12, 2012
1 parent 05fa57c commit 6a448c1
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 76 deletions.
10 changes: 5 additions & 5 deletions backend/app/model/ASModel.rb
Expand Up @@ -228,10 +228,10 @@ def active_repository
#
# For example, this definition from subject.rb:
#
# jsonmodel_hint(:the_property => :terms,
# :contains_records_of_type => :term,
# :corresponding_to_association => :term,
# :always_resolve => true)
# def_nested_record(:the_property => :terms,
# :contains_records_of_type => :term,
# :corresponding_to_association => :term,
# :always_resolve => true)
#
# Causes an incoming JSONModel(:subject) to have each of the objects in its
# "terms" array to be coerced into a Sequel model (based on the :terms
Expand All @@ -245,7 +245,7 @@ def active_repository
# indicates that we want the actual JSON objects to be included in the
# response, not just their URI references.

def jsonmodel_hint(opts)
def def_nested_record(opts)
opts[:association] = self.association_reflection(opts[:corresponding_to_association])
opts[:jsonmodel] = opts[:contains_records_of_type]
opts[:json_property] = opts[:the_property]
Expand Down
19 changes: 9 additions & 10 deletions backend/app/model/agent_manager.rb
Expand Up @@ -42,16 +42,15 @@ def register_agent_type(opts)
self.one_to_many my_agent_type[:name_type]
self.one_to_many :agent_contact

self.jsonmodel_hint(:the_property => :names,
:contains_records_of_type => my_agent_type[:name_type],
:corresponding_to_association => my_agent_type[:name_type],
:always_resolve => true)

self.jsonmodel_hint(:the_property => :agent_contacts,
:contains_records_of_type => :agent_contact,
:corresponding_to_association => :agent_contact,
:always_resolve => true)

self.def_nested_record(:the_property => :names,
:contains_records_of_type => my_agent_type[:name_type],
:corresponding_to_association => my_agent_type[:name_type],
:always_resolve => true)

self.def_nested_record(:the_property => :agent_contacts,
:contains_records_of_type => :agent_contact,
:corresponding_to_association => :agent_contact,
:always_resolve => true)
end


Expand Down
9 changes: 4 additions & 5 deletions backend/app/model/container.rb
Expand Up @@ -6,9 +6,8 @@ class Container < Sequel::Model(:container)

one_to_many :container_location

jsonmodel_hint(:the_property => :container_locations,
:contains_records_of_type => :container_location,
:corresponding_to_association => :container_location,
:always_resolve => true)

def_nested_record(:the_property => :container_locations,
:contains_records_of_type => :container_location,
:corresponding_to_association => :container_location,
:always_resolve => true)
end
8 changes: 4 additions & 4 deletions backend/app/model/container_location.rb
Expand Up @@ -6,10 +6,10 @@ class ContainerLocation < Sequel::Model(:container_location)
corresponds_to JSONModel(:container_location)
many_to_one :location

jsonmodel_hint(:the_property => :location,
:is_array => false,
:contains_records_of_type => :location,
:corresponding_to_association => :location)
def_nested_record(:the_property => :location,
:is_array => false,
:contains_records_of_type => :location,
:corresponding_to_association => :location)

def validate
if self.location_id and self.status === "previous"
Expand Down
8 changes: 4 additions & 4 deletions backend/app/model/dates.rb
Expand Up @@ -6,10 +6,10 @@ module Dates
def self.included(base)
base.one_to_many :date, :class => "ASDate"

base.jsonmodel_hint(:the_property => :dates,
:contains_records_of_type => :date,
:corresponding_to_association => :date,
:always_resolve => true)
base.def_nested_record(:the_property => :dates,
:contains_records_of_type => :date,
:corresponding_to_association => :date,
:always_resolve => true)
end

end
12 changes: 5 additions & 7 deletions backend/app/model/deaccession.rb
Expand Up @@ -6,11 +6,9 @@ class Deaccession < Sequel::Model(:deaccession)
corresponds_to JSONModel(:deaccession)

one_to_one :date, :class => "ASDate"
jsonmodel_hint(:the_property => :date,
:contains_records_of_type => :date,
:corresponding_to_association => :date,
:is_array => false,
:always_resolve => true)


def_nested_record(:the_property => :date,
:contains_records_of_type => :date,
:corresponding_to_association => :date,
:is_array => false,
:always_resolve => true)
end
8 changes: 4 additions & 4 deletions backend/app/model/deaccessions.rb
Expand Up @@ -6,10 +6,10 @@ module Deaccessions
def self.included(base)
base.one_to_many :deaccession

base.jsonmodel_hint(:the_property => :deaccessions,
:contains_records_of_type => :deaccession,
:corresponding_to_association => :deaccession,
:always_resolve => true)
base.def_nested_record(:the_property => :deaccessions,
:contains_records_of_type => :deaccession,
:corresponding_to_association => :deaccession,
:always_resolve => true)
end

end
10 changes: 5 additions & 5 deletions backend/app/model/event.rb
Expand Up @@ -12,11 +12,11 @@ class Event < Sequel::Model(:event)
enable_suppression

one_to_many :date, :class => "ASDate"
jsonmodel_hint(:the_property => :date,
:contains_records_of_type => :date,
:corresponding_to_association => :date,
:is_array => false,
:always_resolve => true)
def_nested_record(:the_property => :date,
:contains_records_of_type => :date,
:corresponding_to_association => :date,
:is_array => false,
:always_resolve => true)

define_relationship(:name => :link,
:json_property => 'linked_records',
Expand Down
8 changes: 4 additions & 4 deletions backend/app/model/extents.rb
Expand Up @@ -6,10 +6,10 @@ module Extents
def self.included(base)
base.one_to_many :extent

base.jsonmodel_hint(:the_property => :extents,
:contains_records_of_type => :extent,
:corresponding_to_association => :extent,
:always_resolve => true)
base.def_nested_record(:the_property => :extents,
:contains_records_of_type => :extent,
:corresponding_to_association => :extent,
:always_resolve => true)
end

end
8 changes: 4 additions & 4 deletions backend/app/model/external_documents.rb
Expand Up @@ -14,10 +14,10 @@ def self.included(base)
},
:join_table => "#{base.table_name}_external_document")

base.jsonmodel_hint(:the_property => :external_documents,
:contains_records_of_type => :external_document,
:corresponding_to_association => :external_document,
:always_resolve => true)
base.def_nested_record(:the_property => :external_documents,
:contains_records_of_type => :external_document,
:corresponding_to_association => :external_document,
:always_resolve => true)
end

end
10 changes: 5 additions & 5 deletions backend/app/model/instance.rb
Expand Up @@ -6,10 +6,10 @@ class Instance < Sequel::Model(:instance)

one_to_many :container

jsonmodel_hint(:the_property => :container,
:is_array => false,
:contains_records_of_type => :container,
:corresponding_to_association => :container,
:always_resolve => true)
def_nested_record(:the_property => :container,
:is_array => false,
:contains_records_of_type => :container,
:corresponding_to_association => :container,
:always_resolve => true)

end
8 changes: 4 additions & 4 deletions backend/app/model/instances.rb
Expand Up @@ -6,10 +6,10 @@ module Instances
def self.included(base)
base.one_to_many :instance

base.jsonmodel_hint(:the_property => :instances,
:contains_records_of_type => :instance,
:corresponding_to_association => :instance,
:always_resolve => true)
base.def_nested_record(:the_property => :instances,
:contains_records_of_type => :instance,
:corresponding_to_association => :instance,
:always_resolve => true)
end

end
8 changes: 4 additions & 4 deletions backend/app/model/rights_statements.rb
Expand Up @@ -6,10 +6,10 @@ module RightsStatements
def self.included(base)
base.one_to_many :rights_statement

base.jsonmodel_hint(:the_property => :rights_statements,
:contains_records_of_type => :rights_statement,
:corresponding_to_association => :rights_statement,
:always_resolve => true)
base.def_nested_record(:the_property => :rights_statements,
:contains_records_of_type => :rights_statement,
:corresponding_to_association => :rights_statement,
:always_resolve => true)
end

end
8 changes: 4 additions & 4 deletions backend/app/model/subject.rb
Expand Up @@ -11,10 +11,10 @@ class Subject < Sequel::Model(:subject)
many_to_many :term, :join_table => :subject_term
many_to_many :archival_object, :join_table => :subject_archival_object

jsonmodel_hint(:the_property => :terms,
:contains_records_of_type => :term,
:corresponding_to_association => :term,
:always_resolve => true)
def_nested_record(:the_property => :terms,
:contains_records_of_type => :term,
:corresponding_to_association => :term,
:always_resolve => true)


def self.set_vocabulary(json, opts)
Expand Down
6 changes: 3 additions & 3 deletions backend/app/model/subjects.rb
Expand Up @@ -6,9 +6,9 @@ module Subjects
def self.included(base)
base.many_to_many :subject, :join_table => "subject_#{base.table_name}", :order => "subject_#{base.table_name}__id".intern

base.jsonmodel_hint(:the_property => :subjects,
:contains_records_of_type => :subject,
:corresponding_to_association => :subject)
base.def_nested_record(:the_property => :subjects,
:contains_records_of_type => :subject,
:corresponding_to_association => :subject)
end

end
8 changes: 4 additions & 4 deletions backend/app/model/vocabulary.rb
Expand Up @@ -7,10 +7,10 @@ class Vocabulary < Sequel::Model(:vocabulary)
one_to_many :subject
one_to_many :term, :key => :vocab_id

jsonmodel_hint(:the_property => :terms,
:contains_records_of_type => :term,
:corresponding_to_association => :term,
:always_resolve => true)
def_nested_record(:the_property => :terms,
:contains_records_of_type => :term,
:corresponding_to_association => :term,
:always_resolve => true)

def self.set(params)
self.where(params)
Expand Down

0 comments on commit 6a448c1

Please sign in to comment.