Revert "set inverse_of for polymorphic associations"

This reverts commit c20d270a4a.

Change-Id: I0227de546fc7ea22efd6b2acb6b77982f52bde52
Reviewed-on: https://gerrit.instructure.com/99570
Reviewed-by: Dan Minkevitch <dan@instructure.com>
Tested-by: Jenkins
Product-Review: Landon Wilkins <lwilkins@instructure.com>
QA-Review: Landon Wilkins <lwilkins@instructure.com>
This commit is contained in:
Landon Wilkins 2017-01-13 18:43:32 +00:00
parent 6d0becc259
commit 7bc6743b0b
31 changed files with 128 additions and 142 deletions

View File

@ -30,9 +30,9 @@ class Account < ActiveRecord::Base
authenticates_many :pseudonym_sessions
has_many :courses
has_many :all_courses, :class_name => 'Course', :foreign_key => 'root_account_id'
has_many :group_categories, -> { where(deleted_at: nil) }, as: :context, inverse_of: :context
has_many :all_group_categories, :class_name => 'GroupCategory', :as => :context, :inverse_of => :context
has_many :groups, :as => :context, :inverse_of => :context
has_many :group_categories, -> { where(deleted_at: nil) }, as: :context
has_many :all_group_categories, :class_name => 'GroupCategory', :as => :context
has_many :groups, :as => :context
has_many :all_groups, :class_name => 'Group', :foreign_key => 'root_account_id'
has_many :all_group_memberships, source: 'group_memberships', through: :all_groups
has_many :enrollment_terms, :foreign_key => 'root_account_id'
@ -50,13 +50,13 @@ class Account < ActiveRecord::Base
has_many :root_abstract_courses, :class_name => 'AbstractCourse', :foreign_key => 'root_account_id'
has_many :users, :through => :account_users
has_many :pseudonyms, -> { preload(:user) }, inverse_of: :account
has_many :role_overrides, :as => :context, :inverse_of => :context
has_many :role_overrides, :as => :context
has_many :course_account_associations
has_many :child_courses, -> { where(course_account_associations: { depth: 0 }) }, through: :course_account_associations, source: :course
has_many :attachments, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :active_assignments, -> { where("assignments.workflow_state<>'deleted'") }, as: :context, inverse_of: :context, class_name: 'Assignment'
has_many :folders, -> { order('folders.name') }, as: :context, inverse_of: :context, dependent: :destroy
has_many :active_folders, -> { where("folder.workflow_state<>'deleted'").order('folders.name') }, class_name: 'Folder', as: :context, inverse_of: :context
has_many :attachments, :as => :context, :dependent => :destroy
has_many :active_assignments, -> { where("assignments.workflow_state<>'deleted'") }, as: :context, class_name: 'Assignment'
has_many :folders, -> { order('folders.name') }, as: :context, dependent: :destroy
has_many :active_folders, -> { where("folder.workflow_state<>'deleted'").order('folders.name') }, class_name: 'Folder', as: :context
has_many :developer_keys
has_many :authentication_providers,
-> { order(:position) },
@ -64,13 +64,13 @@ class Account < ActiveRecord::Base
class_name: "AccountAuthorizationConfig"
has_many :account_reports
has_many :grading_standards, -> { where("workflow_state<>'deleted'") }, as: :context, inverse_of: :context
has_many :grading_standards, -> { where("workflow_state<>'deleted'") }, as: :context
has_many :assessment_questions, :through => :assessment_question_banks
has_many :assessment_question_banks, -> { preload(:assessment_questions, :assessment_question_bank_users) }, as: :context, inverse_of: :context
has_many :assessment_question_banks, -> { preload(:assessment_questions, :assessment_question_bank_users) }, as: :context
has_many :roles
has_many :all_roles, :class_name => 'Role', :foreign_key => 'root_account_id'
has_many :progresses, :as => :context, :inverse_of => :context
has_many :content_migrations, :as => :context, :inverse_of => :context
has_many :progresses, :as => :context
has_many :content_migrations, :as => :context
def inherited_assessment_question_banks(include_self = false, *additional_contexts)
sql = []
@ -88,13 +88,13 @@ class Account < ActiveRecord::Base
include LearningOutcomeContext
include RubricContext
has_many :context_external_tools, -> { order(:name) }, as: :context, inverse_of: :context, dependent: :destroy
has_many :context_external_tools, -> { order(:name) }, as: :context, dependent: :destroy
has_many :error_reports
has_many :announcements, :class_name => 'AccountNotification'
has_many :alerts, -> { preload(:criteria) }, as: :context, inverse_of: :context
has_many :alerts, -> { preload(:criteria) }, as: :context
has_many :user_account_associations
has_many :report_snapshots
has_many :external_integration_keys, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :external_integration_keys, :as => :context, :dependent => :destroy
has_many :shared_brand_configs
belongs_to :brand_config, foreign_key: "brand_config_md5"

View File

@ -22,7 +22,7 @@ class AccountUser < ActiveRecord::Base
belongs_to :role
include Role::AssociationHelper
has_many :role_overrides, :as => :context, :inverse_of => :context
has_many :role_overrides, :as => :context
has_a_broadcast_policy
before_validation :infer_defaults
after_save :touch_user

View File

@ -20,7 +20,7 @@ class AssessmentQuestion < ActiveRecord::Base
include Workflow
has_many :quiz_questions, :class_name => 'Quizzes::QuizQuestion'
has_many :attachments, :as => :context, :inverse_of => :context
has_many :attachments, :as => :context
delegate :context, :context_id, :context_type, :to => :assessment_question_bank
attr_accessor :initial_context
belongs_to :assessment_question_bank, :touch => true

View File

@ -22,7 +22,7 @@ class AssessmentQuestionBank < ActiveRecord::Base
belongs_to :context, polymorphic: [:account, :course]
has_many :assessment_questions, -> { order('assessment_questions.name, assessment_questions.position, assessment_questions.created_at') }
has_many :assessment_question_bank_users
has_many :learning_outcome_alignments, -> { where("content_tags.tag_type='learning_outcome' AND content_tags.workflow_state<>'deleted'").preload(:learning_outcome) }, as: :content, inverse_of: :content, class_name: 'ContentTag'
has_many :learning_outcome_alignments, -> { where("content_tags.tag_type='learning_outcome' AND content_tags.workflow_state<>'deleted'").preload(:learning_outcome) }, as: :content, class_name: 'ContentTag'
has_many :quiz_groups, class_name: 'Quizzes::QuizGroup'
before_save :infer_defaults
after_save :update_alignments

View File

@ -53,14 +53,14 @@ class Assignment < ActiveRecord::Base
has_many :submissions, :dependent => :destroy
has_many :provisional_grades, :through => :submissions
has_many :attachments, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :attachments, :as => :context, :dependent => :destroy
has_many :assignment_student_visibilities
has_one :quiz, class_name: 'Quizzes::Quiz'
belongs_to :assignment_group
has_one :discussion_topic, -> { where(root_topic_id: nil).order(:created_at) }
has_one :wiki_page
has_many :learning_outcome_alignments, -> { where("content_tags.tag_type='learning_outcome' AND content_tags.workflow_state<>'deleted'").preload(:learning_outcome) }, as: :content, inverse_of: :content, class_name: 'ContentTag'
has_one :rubric_association, -> { where(purpose: 'grading').order(:created_at).preload(:rubric) }, as: :association, inverse_of: :association_object
has_many :learning_outcome_alignments, -> { where("content_tags.tag_type='learning_outcome' AND content_tags.workflow_state<>'deleted'").preload(:learning_outcome) }, as: :content, class_name: 'ContentTag'
has_one :rubric_association, -> { where(purpose: 'grading').order(:created_at).preload(:rubric) }, as: :association
has_one :rubric, :through => :rubric_association
has_one :teacher_enrollment, -> { preload(:user).where(enrollments: { workflow_state: 'active', type: 'TeacherEnrollment' }) }, class_name: 'TeacherEnrollment', foreign_key: 'course_id', primary_key: 'context_id'
has_many :ignores, :as => :asset
@ -74,7 +74,7 @@ class Assignment < ActiveRecord::Base
has_many :tool_settings_context_external_tools, through: :assignment_configuration_tool_lookups, source: :tool, source_type: 'ContextExternalTool'
has_many :tool_settings_tool_proxies, through: :assignment_configuration_tool_lookups, source: :tool, source_type: 'Lti::MessageHandler'
has_one :external_tool_tag, :class_name => 'ContentTag', :as => :context, :inverse_of => :context, :dependent => :destroy
has_one :external_tool_tag, :class_name => 'ContentTag', :as => :context, :dependent => :destroy
validates_associated :external_tool_tag, :if => :external_tool?
validate :group_category_changes_ok?
validate :discussion_group_ok?

View File

@ -22,7 +22,7 @@ class ContentExport < ActiveRecord::Base
belongs_to :user
belongs_to :attachment
belongs_to :content_migration
has_many :attachments, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :attachments, :as => :context, :dependent => :destroy
has_one :epub_export
has_a_broadcast_policy
serialize :settings
@ -31,7 +31,7 @@ class ContentExport < ActiveRecord::Base
validates_presence_of :context_id, :workflow_state
has_one :job_progress, :class_name => 'Progress', :as => :context, :inverse_of => :context
has_one :job_progress, :class_name => 'Progress', :as => :context
#export types
COMMON_CARTRIDGE = 'common_cartridge'

View File

@ -28,7 +28,7 @@ class ContentMigration < ActiveRecord::Base
belongs_to :source_course, :class_name => 'Course'
has_one :content_export
has_many :migration_issues
has_one :job_progress, :class_name => 'Progress', :as => :context, :inverse_of => :context
has_one :job_progress, :class_name => 'Progress', :as => :context
serialize :migration_settings
cattr_accessor :export_file_path
before_save :set_started_at_and_finished_at

View File

@ -24,7 +24,7 @@
module ContextModuleItem
# set up the association for the AR class that included this module
def self.included(klass)
klass.has_many :context_module_tags, -> { where("content_tags.tag_type='context_module' AND content_tags.workflow_state<>'deleted'").preload(context_module: :content_tags) }, as: :content, inverse_of: :content, class_name: 'ContentTag'
klass.has_many :context_module_tags, -> { where("content_tags.tag_type='context_module' AND content_tags.workflow_state<>'deleted'").preload(context_module: :content_tags) }, as: :content, class_name: 'ContentTag'
end
# Check if this item is locked for the given user.

View File

@ -29,7 +29,7 @@ class ConversationMessage < ActiveRecord::Base
belongs_to :author, :class_name => 'User'
belongs_to :context, polymorphic: [:account]
has_many :conversation_message_participants
has_many :attachment_associations, :as => :context, :inverse_of => :context
has_many :attachment_associations, :as => :context
# we used to attach submission comments to conversations via this asset
# TODO: remove this column when we're sure we don't want this relation anymore
belongs_to :asset, polymorphic: [:submission]

View File

@ -120,71 +120,71 @@ class Course < ActiveRecord::Base
has_many :users, -> { uniq }, through: :enrollments, source: :user
has_many :current_users, -> { uniq }, through: :current_enrollments, source: :user
has_many :all_current_users, -> { uniq }, through: :all_current_enrollments, source: :user
has_many :group_categories, -> {where(deleted_at: nil) }, as: :context, inverse_of: :context
has_many :all_group_categories, :class_name => 'GroupCategory', :as => :context, :inverse_of => :context
has_many :groups, :as => :context, :inverse_of => :context
has_many :active_groups, -> { where("groups.workflow_state<>'deleted'") }, as: :context, inverse_of: :context, class_name: 'Group'
has_many :assignment_groups, -> { order('assignment_groups.position, assignment_groups.name') }, as: :context, inverse_of: :context, dependent: :destroy
has_many :assignments, -> { order('assignments.created_at') }, as: :context, inverse_of: :context, dependent: :destroy
has_many :calendar_events, -> { where("calendar_events.workflow_state<>'cancelled'") }, as: :context, inverse_of: :context, dependent: :destroy
has_many :group_categories, -> {where(deleted_at: nil) }, as: :context
has_many :all_group_categories, :class_name => 'GroupCategory', :as => :context
has_many :groups, :as => :context
has_many :active_groups, -> { where("groups.workflow_state<>'deleted'") }, as: :context, class_name: 'Group'
has_many :assignment_groups, -> { order('assignment_groups.position, assignment_groups.name') }, as: :context, dependent: :destroy
has_many :assignments, -> { order('assignments.created_at') }, as: :context, dependent: :destroy
has_many :calendar_events, -> { where("calendar_events.workflow_state<>'cancelled'") }, as: :context, dependent: :destroy
has_many :submissions, -> { order('submissions.updated_at DESC') }, through: :assignments, dependent: :destroy
has_many :submission_comments, -> { published }, as: :context, inverse_of: :context
has_many :discussion_topics, -> { where("discussion_topics.workflow_state<>'deleted'").preload(:user).order('discussion_topics.position DESC, discussion_topics.created_at DESC') }, as: :context, inverse_of: :context, dependent: :destroy
has_many :active_discussion_topics, -> { where("discussion_topics.workflow_state<>'deleted'").preload(:user) }, as: :context, inverse_of: :context, class_name: 'DiscussionTopic'
has_many :all_discussion_topics, -> { preload(:user) }, as: :context, inverse_of: :context, class_name: "DiscussionTopic", dependent: :destroy
has_many :submission_comments, -> { published }, as: :context
has_many :discussion_topics, -> { where("discussion_topics.workflow_state<>'deleted'").preload(:user).order('discussion_topics.position DESC, discussion_topics.created_at DESC') }, as: :context, dependent: :destroy
has_many :active_discussion_topics, -> { where("discussion_topics.workflow_state<>'deleted'").preload(:user) }, as: :context, class_name: 'DiscussionTopic'
has_many :all_discussion_topics, -> { preload(:user) }, as: :context, class_name: "DiscussionTopic", dependent: :destroy
has_many :discussion_entries, -> { preload(:discussion_topic, :user) }, through: :discussion_topics, dependent: :destroy
has_many :announcements, :as => :context, :inverse_of => :context, :class_name => 'Announcement', :dependent => :destroy
has_many :active_announcements, -> { where("discussion_topics.workflow_state<>'deleted'") }, as: :context, inverse_of: :context, class_name: 'Announcement'
has_many :attachments, :as => :context, :inverse_of => :context, :dependent => :destroy, :extend => Attachment::FindInContextAssociation
has_many :active_images, -> { where("attachments.file_state<>? AND attachments.content_type LIKE 'image%'", 'deleted').order('attachments.display_name').preload(:thumbnail) }, as: :context, inverse_of: :context, class_name: 'Attachment'
has_many :active_assignments, -> { where("assignments.workflow_state<>'deleted'").order('assignments.title, assignments.position') }, as: :context, inverse_of: :context, class_name: 'Assignment'
has_many :folders, -> { order('folders.name') }, as: :context, inverse_of: :context, dependent: :destroy
has_many :active_folders, -> { where("folders.workflow_state<>'deleted'").order('folders.name') }, class_name: 'Folder', as: :context, inverse_of: :context
has_many :messages, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :context_external_tools, -> { order('name') }, as: :context, inverse_of: :context, dependent: :destroy
has_many :announcements, :as => :context, :class_name => 'Announcement', :dependent => :destroy
has_many :active_announcements, -> { where("discussion_topics.workflow_state<>'deleted'") }, as: :context, class_name: 'Announcement'
has_many :attachments, :as => :context, :dependent => :destroy, :extend => Attachment::FindInContextAssociation
has_many :active_images, -> { where("attachments.file_state<>? AND attachments.content_type LIKE 'image%'", 'deleted').order('attachments.display_name').preload(:thumbnail) }, as: :context, class_name: 'Attachment'
has_many :active_assignments, -> { where("assignments.workflow_state<>'deleted'").order('assignments.title, assignments.position') }, as: :context, class_name: 'Assignment'
has_many :folders, -> { order('folders.name') }, as: :context, dependent: :destroy
has_many :active_folders, -> { where("folders.workflow_state<>'deleted'").order('folders.name') }, class_name: 'Folder', as: :context
has_many :messages, :as => :context, :dependent => :destroy
has_many :context_external_tools, -> { order('name') }, as: :context, dependent: :destroy
belongs_to :wiki
has_many :wiki_pages, foreign_key: 'wiki_id', primary_key: 'wiki_id'
has_many :quizzes, -> { order('lock_at, title, id') }, class_name: 'Quizzes::Quiz', as: :context, inverse_of: :context, dependent: :destroy
has_many :quizzes, -> { order('lock_at, title, id') }, class_name: 'Quizzes::Quiz', as: :context, dependent: :destroy
has_many :quiz_questions, :class_name => 'Quizzes::QuizQuestion', :through => :quizzes
has_many :active_quizzes, -> { preload(:assignment).where("quizzes.workflow_state<>'deleted'").order(:created_at) }, class_name: 'Quizzes::Quiz', as: :context, inverse_of: :context
has_many :active_quizzes, -> { preload(:assignment).where("quizzes.workflow_state<>'deleted'").order(:created_at) }, class_name: 'Quizzes::Quiz', as: :context
has_many :assessment_questions, :through => :assessment_question_banks
has_many :assessment_question_banks, -> { preload(:assessment_questions, :assessment_question_bank_users) }, as: :context, inverse_of: :context
has_many :assessment_question_banks, -> { preload(:assessment_questions, :assessment_question_bank_users) }, as: :context
def inherited_assessment_question_banks(include_self = false)
self.account.inherited_assessment_question_banks(true, *(include_self ? [self] : []))
end
has_many :external_feeds, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :external_feeds, :as => :context, :dependent => :destroy
belongs_to :default_grading_standard, :class_name => 'GradingStandard', :foreign_key => 'grading_standard_id'
has_many :grading_standards, -> { where("workflow_state<>'deleted'") }, as: :context, inverse_of: :context
has_many :web_conferences, -> { order('created_at DESC') }, as: :context, inverse_of: :context, dependent: :destroy
has_many :collaborations, -> { order("#{Collaboration.quoted_table_name}.title, #{Collaboration.quoted_table_name}.created_at") }, as: :context, inverse_of: :context, dependent: :destroy
has_many :context_modules, -> { order(:position) }, as: :context, inverse_of: :context, dependent: :destroy
has_many :grading_standards, -> { where("workflow_state<>'deleted'") }, as: :context
has_many :web_conferences, -> { order('created_at DESC') }, as: :context, dependent: :destroy
has_many :collaborations, -> { order("#{Collaboration.quoted_table_name}.title, #{Collaboration.quoted_table_name}.created_at") }, as: :context, dependent: :destroy
has_many :context_modules, -> { order(:position) }, as: :context, dependent: :destroy
has_many :context_module_progressions, through: :context_modules
has_many :active_context_modules, -> { where(workflow_state: 'active') }, as: :context, inverse_of: :context, class_name: 'ContextModule'
has_many :context_module_tags, -> { order(:position).where(tag_type: 'context_module') }, class_name: 'ContentTag', as: :context, inverse_of: :context, dependent: :destroy
has_many :media_objects, :as => :context, :inverse_of => :context
has_many :page_views, :as => :context, :inverse_of => :context
has_many :asset_user_accesses, :as => :context, :inverse_of => :context
has_many :role_overrides, :as => :context, :inverse_of => :context
has_many :content_migrations, :as => :context, :inverse_of => :context
has_many :content_exports, :as => :context, :inverse_of => :context
has_many :active_context_modules, -> { where(workflow_state: 'active') }, as: :context, class_name: 'ContextModule'
has_many :context_module_tags, -> { order(:position).where(tag_type: 'context_module') }, class_name: 'ContentTag', as: 'context', dependent: :destroy
has_many :media_objects, :as => :context
has_many :page_views, :as => :context
has_many :asset_user_accesses, :as => :context
has_many :role_overrides, :as => :context
has_many :content_migrations, :as => :context
has_many :content_exports, :as => :context
has_many :epub_exports, -> { where("type IS NULL").order("created_at DESC") }
attr_accessor :latest_epub_export
has_many :web_zip_exports, -> { where(type: "WebZipExport") }
has_many :alerts, -> { preload(:criteria) }, as: :context, inverse_of: :context
has_many :appointment_group_contexts, :as => :context, :inverse_of => :context
has_many :alerts, -> { preload(:criteria) }, as: :context
has_many :appointment_group_contexts, :as => :context
has_many :appointment_groups, :through => :appointment_group_contexts
has_many :appointment_participants, -> { where("workflow_state = 'locked' AND parent_calendar_event_id IS NOT NULL") }, class_name: 'CalendarEvent', foreign_key: :effective_context_code, primary_key: :asset_string
attr_accessor :import_source
has_many :content_participation_counts, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :content_participation_counts, :as => :context, :dependent => :destroy
has_many :poll_sessions, class_name: 'Polling::PollSession', dependent: :destroy
has_many :grading_period_groups, dependent: :destroy
has_many :grading_periods, through: :grading_period_groups
has_many :usage_rights, as: :context, inverse_of: :context, class_name: 'UsageRights', dependent: :destroy
has_many :usage_rights, as: :context, class_name: 'UsageRights', dependent: :destroy
has_many :sis_post_grades_statuses
has_many :progresses, as: :context, inverse_of: :context
has_many :progresses, as: :context
has_many :gradebook_csvs, inverse_of: :course
has_many :master_course_templates, :class_name => "MasterCourses::MasterTemplate"

View File

@ -32,7 +32,7 @@ class CourseSection < ActiveRecord::Base
has_many :admin_enrollments, -> { where(type: ['TaEnrollment', 'TeacherEnrollment', 'DesignerEnrollment']) }, class_name: 'Enrollment'
has_many :users, :through => :enrollments
has_many :course_account_associations
has_many :calendar_events, :as => :context, :inverse_of => :context
has_many :calendar_events, :as => :context
has_many :assignment_overrides, :as => :set, :dependent => :destroy
before_validation :infer_defaults, :verify_unique_sis_source_id

View File

@ -41,7 +41,7 @@ class Enrollment < ActiveRecord::Base
has_one :enrollment_state, :dependent => :destroy
has_many :role_overrides, :as => :context, :inverse_of => :context
has_many :role_overrides, :as => :context
has_many :pseudonyms, :primary_key => :user_id, :foreign_key => :user_id
has_many :course_account_associations, :foreign_key => 'course_id', :primary_key => 'course_id'
has_many :scores, -> { active }, dependent: :destroy

View File

@ -20,7 +20,7 @@ class Eportfolio < ActiveRecord::Base
include Workflow
has_many :eportfolio_categories, -> { order(:position) }, dependent: :destroy
has_many :eportfolio_entries, :dependent => :destroy
has_many :attachments, :as => :context, :inverse_of => :context
has_many :attachments, :as => :context
belongs_to :user
validates_presence_of :user_id

View File

@ -6,10 +6,10 @@ class EpubExport < ActiveRecord::Base
belongs_to :content_export
belongs_to :course
belongs_to :user
has_many :attachments, -> { order('created_at DESC') }, dependent: :destroy, as: :context, inverse_of: :context, class_name: 'Attachment'
has_one :epub_attachment, -> { where(content_type: 'application/epub+zip').order('created_at DESC') }, as: :context, inverse_of: :context, class_name: 'Attachment'
has_one :zip_attachment, -> { where(content_type: 'application/zip').order('created_at DESC') }, as: :context, inverse_of: :context, class_name: 'Attachment'
has_one :job_progress, as: :context, inverse_of: :context, class_name: 'Progress'
has_many :attachments, -> { order('created_at DESC') }, dependent: :destroy, as: :context, class_name: 'Attachment'
has_one :epub_attachment, -> { where(content_type: 'application/epub+zip').order('created_at DESC') }, as: :context, class_name: 'Attachment'
has_one :zip_attachment, -> { where(content_type: 'application/zip').order('created_at DESC') }, as: :context, class_name: 'Attachment'
has_one :job_progress, as: :context, class_name: 'Progress'
validates :course_id, :workflow_state, presence: true
PERCENTAGE_COMPLETE = {

View File

@ -20,7 +20,7 @@ class GradebookUpload < ActiveRecord::Base
belongs_to :course
belongs_to :user
belongs_to :progress
has_many :attachments, as: :context, inverse_of: :context, dependent: :destroy
has_many :attachments, as: :context, dependent: :destroy
serialize :gradebook, JSON

View File

@ -37,31 +37,31 @@ class Group < ActiveRecord::Base
belongs_to :group_category
belongs_to :account
belongs_to :root_account, :class_name => "Account"
has_many :calendar_events, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :discussion_topics, -> { where("discussion_topics.workflow_state<>'deleted'").preload(:user).order('discussion_topics.position DESC, discussion_topics.created_at DESC') }, dependent: :destroy, as: :context, inverse_of: :context
has_many :active_discussion_topics, -> { where("discussion_topics.workflow_state<>'deleted'").preload(:user) }, as: :context, inverse_of: :context, class_name: 'DiscussionTopic'
has_many :all_discussion_topics, -> { preload(:user) }, as: :context, inverse_of: :context, class_name: "DiscussionTopic", dependent: :destroy
has_many :calendar_events, :as => :context, :dependent => :destroy
has_many :discussion_topics, -> { where("discussion_topics.workflow_state<>'deleted'").preload(:user).order('discussion_topics.position DESC, discussion_topics.created_at DESC') }, dependent: :destroy, as: :context
has_many :active_discussion_topics, -> { where("discussion_topics.workflow_state<>'deleted'").preload(:user) }, as: :context, class_name: 'DiscussionTopic'
has_many :all_discussion_topics, -> { preload(:user) }, as: :context, class_name: "DiscussionTopic", dependent: :destroy
has_many :discussion_entries, -> { preload(:discussion_topic, :user) }, through: :discussion_topics, dependent: :destroy
has_many :announcements, :as => :context, :inverse_of => :context, :class_name => 'Announcement', :dependent => :destroy
has_many :active_announcements, -> { where("discussion_topics.workflow_state<>'deleted'") }, as: :context, inverse_of: :context, class_name: 'Announcement'
has_many :attachments, :as => :context, :inverse_of => :context, :dependent => :destroy, :extend => Attachment::FindInContextAssociation
has_many :active_images, -> { where("attachments.file_state<>'deleted' AND attachments.content_type LIKE 'image%'").order('attachments.display_name').preload(:thumbnail) }, as: :context, inverse_of: :context, class_name: 'Attachment'
has_many :active_assignments, -> { where("assignments.workflow_state<>'deleted'") }, as: :context, inverse_of: :context, class_name: 'Assignment'
has_many :announcements, :as => :context, :class_name => 'Announcement', :dependent => :destroy
has_many :active_announcements, -> { where("discussion_topics.workflow_state<>'deleted'") }, as: :context, class_name: 'Announcement'
has_many :attachments, :as => :context, :dependent => :destroy, :extend => Attachment::FindInContextAssociation
has_many :active_images, -> { where("attachments.file_state<>'deleted' AND attachments.content_type LIKE 'image%'").order('attachments.display_name').preload(:thumbnail) }, as: :context, class_name: 'Attachment'
has_many :active_assignments, -> { where("assignments.workflow_state<>'deleted'") }, as: :context, class_name: 'Assignment'
has_many :all_attachments, :as => 'context', :class_name => 'Attachment'
has_many :folders, -> { order('folders.name') }, as: :context, inverse_of: :context, dependent: :destroy
has_many :active_folders, -> { where("folders.workflow_state<>'deleted'").order('folders.name') }, class_name: 'Folder', as: :context, inverse_of: :context
has_many :submissions_folders, -> { where.not(:folders => {:submission_context_code => nil}) }, as: :context, inverse_of: :context, class_name: 'Folder'
has_many :folders, -> { order('folders.name') }, as: :context, dependent: :destroy
has_many :active_folders, -> { where("folders.workflow_state<>'deleted'").order('folders.name') }, class_name: 'Folder', as: :context
has_many :submissions_folders, -> { where.not(:folders => {:submission_context_code => nil}) }, as: 'context', class_name: 'Folder'
has_many :collaborators
has_many :external_feeds, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :messages, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :external_feeds, :as => :context, :dependent => :destroy
has_many :messages, :as => :context, :dependent => :destroy
belongs_to :wiki
has_many :wiki_pages, foreign_key: 'wiki_page', primary_key: 'wiki_page'
has_many :web_conferences, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :collaborations, -> { order("#{Collaboration.quoted_table_name}.title, #{Collaboration.quoted_table_name}.created_at") }, as: :context, inverse_of: :context, dependent: :destroy
has_many :media_objects, :as => :context, :inverse_of => :context
has_many :content_migrations, :as => :context, :inverse_of => :context
has_many :content_exports, :as => :context, :inverse_of => :context
has_many :usage_rights, as: :context, inverse_of: :context, class_name: 'UsageRights', dependent: :destroy
has_many :web_conferences, :as => :context, :dependent => :destroy
has_many :collaborations, -> { order("#{Collaboration.quoted_table_name}.title, #{Collaboration.quoted_table_name}.created_at") }, as: :context, dependent: :destroy
has_many :media_objects, :as => :context
has_many :content_migrations, :as => :context
has_many :content_exports, :as => :context
has_many :usage_rights, as: :context, class_name: 'UsageRights', dependent: :destroy
belongs_to :avatar_attachment, :class_name => "Attachment"
belongs_to :leader, :class_name => "User"

View File

@ -24,7 +24,7 @@ class GroupCategory < ActiveRecord::Base
has_many :groups, :dependent => :destroy
has_many :assignments, :dependent => :nullify
has_many :progresses, :as => 'context', :dependent => :destroy
has_one :current_progress, -> { where(workflow_state: ['queued', 'running']).order(:created_at) }, as: :context, inverse_of: :context, class_name: 'Progress'
has_one :current_progress, -> { where(workflow_state: ['queued', 'running']).order(:created_at) }, as: 'context', class_name: 'Progress'
after_save :auto_create_groups
after_update :update_groups_max_membership

View File

@ -22,7 +22,7 @@ module LiveAssessments
has_many :submissions, class_name: 'LiveAssessments::Submission'
has_many :results, class_name: 'LiveAssessments::Result'
has_many :learning_outcome_alignments, -> { where("content_tags.tag_type='learning_outcome' AND content_tags.workflow_state<>'deleted'").preload(:learning_outcome) }, as: :content, inverse_of: :content, class_name: 'ContentTag'
has_many :learning_outcome_alignments, -> { where("content_tags.tag_type='learning_outcome' AND content_tags.workflow_state<>'deleted'").preload(:learning_outcome) }, as: :content, class_name: 'ContentTag'
validates_presence_of :context_id, :context_type, :key, :title
validates_length_of :title, maximum: maximum_string_length

View File

@ -28,7 +28,7 @@ module Lti
has_many :placements, class_name: 'Lti::ResourcePlacement', dependent: :destroy
has_many :context_module_tags, -> { where("content_tags.tag_type='context_module' AND content_tags.workflow_state<>'deleted'").preload(context_module: :content_tags) }, as: :content, inverse_of: :content, class_name: 'ContentTag'
has_many :context_module_tags, -> { where("content_tags.tag_type='context_module' AND content_tags.workflow_state<>'deleted'").preload(context_module: :content_tags) }, as: :content, class_name: 'ContentTag'
serialize :capabilities
serialize :parameters

View File

@ -41,7 +41,7 @@ class Message < ActiveRecord::Base
include NotificationPreloader
belongs_to :user
belongs_to :root_account, :class_name => 'Account'
has_many :attachments, :as => :context, :inverse_of => :context
has_many :attachments, :as => :context
attr_writer :delayed_messages
attr_accessor :output_buffer

View File

@ -93,7 +93,7 @@ class Profile < ActiveRecord::Base
module Association
def self.prepended(klass)
klass.has_one :profile, as: :context, inverse_of: :context
klass.has_one :profile, as: :context
end
def profile

View File

@ -37,7 +37,7 @@ class Quizzes::Quiz < ActiveRecord::Base
has_many :quiz_submissions, :dependent => :destroy, :class_name => 'Quizzes::QuizSubmission'
has_many :quiz_groups, -> { order(:position) }, dependent: :destroy, class_name: 'Quizzes::QuizGroup'
has_many :quiz_statistics, -> { order(:created_at) }, class_name: 'Quizzes::QuizStatistics'
has_many :attachments, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :attachments, :as => :context, :dependent => :destroy
has_many :quiz_regrades, class_name: 'Quizzes::QuizRegrade'
has_many :quiz_student_visibilities
belongs_to :context, polymorphic: [:course]
@ -71,7 +71,7 @@ class Quizzes::Quiz < ActiveRecord::Base
simply_versioned
has_many :context_module_tags, -> { where("content_tags.tag_type='context_module' AND content_tags.workflow_state<>'deleted'")}, as: :content, inverse_of: :content, class_name: 'ContentTag'
has_many :context_module_tags, -> { where("content_tags.tag_type='context_module' AND content_tags.workflow_state<>'deleted'")}, as: :content, class_name: 'ContentTag'
# This callback is listed here in order for the :link_assignment_overrides
# method to be called after the simply_versioned callbacks. We want the

View File

@ -50,7 +50,7 @@ class Quizzes::QuizSubmission < ActiveRecord::Base
after_save :context_module_action
before_create :assign_validation_token
has_many :attachments, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :attachments, :as => :context, :dependent => :destroy
has_many :events, class_name: 'Quizzes::QuizSubmissionEvent'
# update the QuizSubmission's Submission to 'graded' when the QuizSubmission is marked as 'complete.' this

View File

@ -25,7 +25,7 @@ class Rubric < ActiveRecord::Base
belongs_to :context, polymorphic: [:course, :account]
has_many :rubric_associations, :class_name => 'RubricAssociation', :dependent => :destroy
has_many :rubric_assessments, :through => :rubric_associations, :dependent => :destroy
has_many :learning_outcome_alignments, -> { where("content_tags.tag_type='learning_outcome' AND content_tags.workflow_state<>'deleted'").preload(:learning_outcome) }, as: :content, inverse_of: :content, class_name: 'ContentTag'
has_many :learning_outcome_alignments, -> { where("content_tags.tag_type='learning_outcome' AND content_tags.workflow_state<>'deleted'").preload(:learning_outcome) }, as: :content, class_name: 'ContentTag'
validates_presence_of :context_id, :context_type, :workflow_state
validates_length_of :description, :maximum => maximum_text_length, :allow_nil => true, :allow_blank => true

View File

@ -71,10 +71,10 @@ class Submission < ActiveRecord::Base
has_many :assessment_requests, :as => :asset
has_many :assigned_assessments, :class_name => 'AssessmentRequest', :as => :assessor_asset
has_many :rubric_assessments, :as => :artifact
has_many :attachment_associations, :as => :context, :inverse_of => :context
has_many :attachment_associations, :as => :context
has_many :provisional_grades, class_name: 'ModeratedGrading::ProvisionalGrade'
has_many :originality_reports
has_one :rubric_assessment, -> { where(assessment_type: 'grading') }, as: :artifact, inverse_of: :artifact
has_one :rubric_assessment, -> { where(assessment_type: 'grading') }, as: :artifact
# we no longer link submission comments and conversations, but we haven't fixed up existing
# linked conversations so this relation might be useful

View File

@ -26,7 +26,7 @@ class SubmissionComment < ActiveRecord::Base
belongs_to :context, polymorphic: [:course]
belongs_to :provisional_grade, :class_name => 'ModeratedGrading::ProvisionalGrade'
has_many :submission_comment_participants, :dependent => :destroy
has_many :messages, :as => :context, :inverse_of => :context, :dependent => :destroy
has_many :messages, :as => :context, :dependent => :destroy
validates_length_of :comment, :maximum => maximum_text_length, :allow_nil => true, :allow_blank => true
validates_length_of :comment, :minimum => 1, :allow_nil => true, :allow_blank => true

View File

@ -72,7 +72,7 @@ class User < ActiveRecord::Base
has_many :associated_root_accounts, -> { order("user_account_associations.depth").where(accounts: { parent_account_id: nil }) }, source: :account, through: :user_account_associations
has_many :developer_keys
has_many :access_tokens, -> { preload(:developer_key) }
has_many :context_external_tools, -> { order(:name) }, as: :context, inverse_of: :context, dependent: :destroy
has_many :context_external_tools, -> { order(:name) }, as: :context, dependent: :destroy
has_many :student_enrollments
has_many :ta_enrollments
@ -83,23 +83,23 @@ class User < ActiveRecord::Base
has_many :pseudonym_accounts, :source => :account, :through => :pseudonyms
has_one :pseudonym, -> { where("pseudonyms.workflow_state<>'deleted'").order(:position) }
has_many :attachments, :as => 'context', :dependent => :destroy
has_many :active_images, -> { where("attachments.file_state != ? AND attachments.content_type LIKE 'image%'", 'deleted').order('attachments.display_name').preload(:thumbnail) }, as: :context, inverse_of: :context, class_name: 'Attachment'
has_many :active_assignments, -> { where("assignments.workflow_state<>'deleted'") }, as: :context, inverse_of: :context, class_name: 'Assignment'
has_many :active_images, -> { where("attachments.file_state != ? AND attachments.content_type LIKE 'image%'", 'deleted').order('attachments.display_name').preload(:thumbnail) }, as: :context, class_name: 'Attachment'
has_many :active_assignments, -> { where("assignments.workflow_state<>'deleted'") }, as: :context, class_name: 'Assignment'
has_many :all_attachments, :as => 'context', :class_name => 'Attachment'
has_many :assignment_student_visibilities
has_many :quiz_student_visibilities, :class_name => 'Quizzes::QuizStudentVisibility'
has_many :folders, -> { order('folders.name') }, as: :context, inverse_of: :context
has_many :submissions_folders, -> { where.not(:folders => {:submission_context_code => nil}) }, as: :context, inverse_of: :context, class_name: 'Folder'
has_many :active_folders, -> { where("folders.workflow_state<>'deleted'").order('folders.name') }, class_name: 'Folder', as: :context, inverse_of: :context
has_many :calendar_events, -> { preload(:parent_event) }, as: :context, inverse_of: :context, dependent: :destroy
has_many :folders, -> { order('folders.name') }, as: 'context'
has_many :submissions_folders, -> { where.not(:folders => {:submission_context_code => nil}) }, as: 'context', class_name: 'Folder'
has_many :active_folders, -> { where("folders.workflow_state<>'deleted'").order('folders.name') }, class_name: 'Folder', as: :context
has_many :calendar_events, -> { preload(:parent_event) }, as: 'context', dependent: :destroy
has_many :eportfolios, :dependent => :destroy
has_many :quiz_submissions, :dependent => :destroy, :class_name => 'Quizzes::QuizSubmission'
has_many :dashboard_messages, -> { where(to: "dashboard", workflow_state: 'dashboard').order('created_at DESC') }, class_name: 'Message', dependent: :destroy
has_many :collaborations, -> { order('created_at DESC') }
has_many :user_services, -> { order('created_at') }, dependent: :destroy
has_many :rubric_associations, -> { preload(:rubric).order('rubric_associations.created_at DESC') }, as: :context, inverse_of: :context
has_many :rubric_associations, -> { preload(:rubric).order('rubric_associations.created_at DESC') }, as: :context
has_many :rubrics
has_many :context_rubrics, :as => :context, :inverse_of => :context, :class_name => 'Rubric'
has_many :context_rubrics, :as => :context, :class_name => 'Rubric'
has_many :grading_standards, -> { where("workflow_state<>'deleted'") }
has_many :context_module_progressions
has_many :assessment_question_bank_users
@ -117,7 +117,7 @@ class User < ActiveRecord::Base
has_many :web_conferences, :through => :web_conference_participants
has_many :account_users
has_many :accounts, :through => :account_users
has_many :media_objects, :as => :context, :inverse_of => :context
has_many :media_objects, :as => :context
has_many :user_generated_media_objects, :class_name => 'MediaObject'
has_many :user_notes
has_many :account_reports
@ -128,10 +128,10 @@ class User < ActiveRecord::Base
has_many :messages
has_many :sis_batches
has_many :sis_post_grades_statuses
has_many :content_migrations, :as => :context, :inverse_of => :context
has_many :content_exports, :as => :context, :inverse_of => :context
has_many :content_migrations, :as => :context
has_many :content_exports, :as => :context
has_many :usage_rights,
as: :context, inverse_of: :context,
as: :context,
class_name: 'UsageRights',
dependent: :destroy
has_many :gradebook_csvs, dependent: :destroy
@ -139,7 +139,7 @@ class User < ActiveRecord::Base
has_one :profile, :class_name => 'UserProfile'
alias :orig_profile :profile
has_many :progresses, :as => :context, :inverse_of => :context
has_many :progresses, :as => :context
belongs_to :otp_communication_channel, :class_name => 'CommunicationChannel'

View File

@ -18,7 +18,7 @@
module FeatureFlags
def self.included(base)
base.has_many :feature_flags, as: :context, inverse_of: :context, dependent: :destroy
base.has_many :feature_flags, as: :context, dependent: :destroy
end
def feature_enabled?(feature)

View File

@ -2,9 +2,9 @@ module LearningOutcomeContext
def self.included(klass)
if klass < ActiveRecord::Base
klass.has_many :linked_learning_outcomes, -> { where(content_tags: { content_type: 'LearningOutcome' }) }, through: :learning_outcome_links, source: :learning_outcome_content
klass.has_many :learning_outcome_links, -> { where("content_tags.tag_type='learning_outcome_association' AND content_tags.workflow_state<>'deleted'") }, as: :context, inverse_of: :context, class_name: 'ContentTag'
klass.has_many :created_learning_outcomes, :class_name => 'LearningOutcome', :as => :context, :inverse_of => :context
klass.has_many :learning_outcome_groups, :as => :context, :inverse_of => :context
klass.has_many :learning_outcome_links, -> { where("content_tags.tag_type='learning_outcome_association' AND content_tags.workflow_state<>'deleted'") }, as: :context, class_name: 'ContentTag'
klass.has_many :created_learning_outcomes, :class_name => 'LearningOutcome', :as => :context
klass.has_many :learning_outcome_groups, :as => :context
klass.send :include, InstanceMethods
end
end

View File

@ -1,8 +1,8 @@
module RubricContext
def self.included(klass)
if klass < ActiveRecord::Base
klass.has_many :rubrics, :as => :context, :inverse_of => :context
klass.has_many :rubric_associations, -> { preload(:rubric) }, as: :context, inverse_of: :context, dependent: :destroy
klass.has_many :rubrics, :as => :context
klass.has_many :rubric_associations, -> { preload(:rubric) }, as: :context, dependent: :destroy
klass.send :include, InstanceMethods
end
end

View File

@ -712,18 +712,4 @@ describe ActiveRecord::Base do
expect(v).to be_valid
end
end
describe "temp_record" do
it "should not reload the base association for normal invertible associations" do
c = Course.create!(:name => "some name")
Course.where(:id => c).update_all(:name => "sadness")
expect(c.enrollments.temp_record.course.name).to eq c.name
end
it "should not reload the base association for polymorphic associations" do
c = Course.create!(:name => "some name")
Course.where(:id => c).update_all(:name => "sadness")
expect(c.discussion_topics.temp_record.course.name).to eq c.name
end
end
end