Class: BiologicalAssociation

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::Citations, Shared::Confidences, Shared::DataAttributes, Shared::Depictions, Shared::Identifiers, Shared::IsData, Shared::Notes, Shared::Tags, SoftValidation
Defined in:
app/models/biological_association.rb

Overview

A BiologicalAssociation defines a (biological) relationship between two entities. It is an edge in the graph of biological relationships. The relationship can be between two Otus, an Otu and a Collection Object, or between two Collection Objects. For example 'Species Aus bus is the host_of individual A.'

Constant Summary

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Depictions

#has_depictions?, #image_array=, #reject_depictions, #reject_images

Methods included from Shared::Notes

#concatenated_notes_string, #reject_notes

Methods included from Shared::DataAttributes

#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes

Methods included from SoftValidation

#clear_soft_validations, #fix_for, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations, #soft_validators

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Attribute Details

#biological_association_object_idInteger

Returns Rails polymorphic, id of the object.

Returns:

  • (Integer)

    Rails polymorphic, id of the object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/biological_association.rb', line 29

class BiologicalAssociation < ApplicationRecord
  include Housekeeping
  include SoftValidation
  include Shared::Citations
  include Shared::Tags
  include Shared::Identifiers
  include Shared::DataAttributes
  include Shared::Confidences
  include Shared::Notes
  include Shared::Confidences
  include Shared::Depictions
  include Shared::IsData

  belongs_to :biological_relationship, inverse_of: :biological_associations

  has_many :subject_biological_relationship_types, through: :biological_relationship
  has_many :object_biological_relationship_types, through: :biological_relationship

  has_many :subject_biological_properties, through: :subject_biological_relationship_types, source: :biological_property
  has_many :object_biological_properties, through: :object_biological_relationship_types, source: :biological_property

  belongs_to :biological_association_subject, polymorphic: true
  belongs_to :biological_association_object, polymorphic: true
  has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_association, dependent: :destroy
  has_many :biological_associations_graphs, through: :biological_associations_biological_associations_graphs, inverse_of: :biological_associations

  validates :biological_relationship, presence: true
  validates :biological_association_subject, presence: true
  validates :biological_association_object, presence: true

  validates_uniqueness_of :biological_association_subject_id, scope: [:biological_association_subject_type, :biological_association_object_id, :biological_association_object_type, :biological_relationship_id]

  validate :biological_association_subject_type_is_allowed
  validate :biological_association_object_type_is_allowed

  attr_accessor :subject_global_id
  attr_accessor :object_global_id # TODO: this is badly named

  # TODO: Why?! this is just biological_association.biological_association_subject_type
  def subject_class_name
    biological_association_subject.try(:class).base_class.name
  end

  # TODO: Why?! this is just biological_association.biological_association_object_type
  def object_class_name
    biological_association_object.try(:class).base_class.name
  end

  def subject_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_subject_id, o.id)
    write_attribute(:biological_association_subject_type, o.metamorphosize.class.name)
  end

  def object_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_object_id, o.id)
    write_attribute(:biological_association_object_type, o.metamorphosize.class.name)
  end

  # @return [ActiveRecord::Relation]
   #def self.collection_objects_subject_join
   #  a = arel_table
   #  b = ::CollectionObject.arel_table
   #  j = a.join(b).on(a[:biological_association_subject_type].eq('CollectionObject').and(a[:biological_association_subject_id].eq(b[:id])))
   #  joins(j.join_sources)
   #end

  # @return [ActiveRecord::Relation]
  def self.targeted_join(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  # @return [ActiveRecord::Relation]
  def self.targeted_join2(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
  end

  # Not used
  # @return [ActiveRecord::Relation]
  def self.targeted_left_join(target: 'subject', target_class: ::Otu )
    a = arel_table
    b = target_class.arel_table

    j = a.join(b, Arel::Nodes::OuterJoin).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  private

  def biological_association_subject_type_is_allowed
    errors.add(:biological_association_subject_type, 'is not permitted') unless biological_association_subject && biological_association_subject.class.is_biologically_relatable?
  end

  def biological_association_object_type_is_allowed
    errors.add(:biological_association_object_type, 'is not permitted') unless biological_association_object && biological_association_object.class.is_biologically_relatable?
  end

end

#biological_association_object_typeString

Returns Rails polymorphic, type of the object (e.g. CollectionObject).

Returns:

  • (String)

    Rails polymorphic, type of the object (e.g. CollectionObject)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/biological_association.rb', line 29

class BiologicalAssociation < ApplicationRecord
  include Housekeeping
  include SoftValidation
  include Shared::Citations
  include Shared::Tags
  include Shared::Identifiers
  include Shared::DataAttributes
  include Shared::Confidences
  include Shared::Notes
  include Shared::Confidences
  include Shared::Depictions
  include Shared::IsData

  belongs_to :biological_relationship, inverse_of: :biological_associations

  has_many :subject_biological_relationship_types, through: :biological_relationship
  has_many :object_biological_relationship_types, through: :biological_relationship

  has_many :subject_biological_properties, through: :subject_biological_relationship_types, source: :biological_property
  has_many :object_biological_properties, through: :object_biological_relationship_types, source: :biological_property

  belongs_to :biological_association_subject, polymorphic: true
  belongs_to :biological_association_object, polymorphic: true
  has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_association, dependent: :destroy
  has_many :biological_associations_graphs, through: :biological_associations_biological_associations_graphs, inverse_of: :biological_associations

  validates :biological_relationship, presence: true
  validates :biological_association_subject, presence: true
  validates :biological_association_object, presence: true

  validates_uniqueness_of :biological_association_subject_id, scope: [:biological_association_subject_type, :biological_association_object_id, :biological_association_object_type, :biological_relationship_id]

  validate :biological_association_subject_type_is_allowed
  validate :biological_association_object_type_is_allowed

  attr_accessor :subject_global_id
  attr_accessor :object_global_id # TODO: this is badly named

  # TODO: Why?! this is just biological_association.biological_association_subject_type
  def subject_class_name
    biological_association_subject.try(:class).base_class.name
  end

  # TODO: Why?! this is just biological_association.biological_association_object_type
  def object_class_name
    biological_association_object.try(:class).base_class.name
  end

  def subject_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_subject_id, o.id)
    write_attribute(:biological_association_subject_type, o.metamorphosize.class.name)
  end

  def object_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_object_id, o.id)
    write_attribute(:biological_association_object_type, o.metamorphosize.class.name)
  end

  # @return [ActiveRecord::Relation]
   #def self.collection_objects_subject_join
   #  a = arel_table
   #  b = ::CollectionObject.arel_table
   #  j = a.join(b).on(a[:biological_association_subject_type].eq('CollectionObject').and(a[:biological_association_subject_id].eq(b[:id])))
   #  joins(j.join_sources)
   #end

  # @return [ActiveRecord::Relation]
  def self.targeted_join(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  # @return [ActiveRecord::Relation]
  def self.targeted_join2(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
  end

  # Not used
  # @return [ActiveRecord::Relation]
  def self.targeted_left_join(target: 'subject', target_class: ::Otu )
    a = arel_table
    b = target_class.arel_table

    j = a.join(b, Arel::Nodes::OuterJoin).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  private

  def biological_association_subject_type_is_allowed
    errors.add(:biological_association_subject_type, 'is not permitted') unless biological_association_subject && biological_association_subject.class.is_biologically_relatable?
  end

  def biological_association_object_type_is_allowed
    errors.add(:biological_association_object_type, 'is not permitted') unless biological_association_object && biological_association_object.class.is_biologically_relatable?
  end

end

#biological_association_subject_idInteger

Returns Rails polymorphic, id of the subject of the relationship.

Returns:

  • (Integer)

    Rails polymorphic, id of the subject of the relationship



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/biological_association.rb', line 29

class BiologicalAssociation < ApplicationRecord
  include Housekeeping
  include SoftValidation
  include Shared::Citations
  include Shared::Tags
  include Shared::Identifiers
  include Shared::DataAttributes
  include Shared::Confidences
  include Shared::Notes
  include Shared::Confidences
  include Shared::Depictions
  include Shared::IsData

  belongs_to :biological_relationship, inverse_of: :biological_associations

  has_many :subject_biological_relationship_types, through: :biological_relationship
  has_many :object_biological_relationship_types, through: :biological_relationship

  has_many :subject_biological_properties, through: :subject_biological_relationship_types, source: :biological_property
  has_many :object_biological_properties, through: :object_biological_relationship_types, source: :biological_property

  belongs_to :biological_association_subject, polymorphic: true
  belongs_to :biological_association_object, polymorphic: true
  has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_association, dependent: :destroy
  has_many :biological_associations_graphs, through: :biological_associations_biological_associations_graphs, inverse_of: :biological_associations

  validates :biological_relationship, presence: true
  validates :biological_association_subject, presence: true
  validates :biological_association_object, presence: true

  validates_uniqueness_of :biological_association_subject_id, scope: [:biological_association_subject_type, :biological_association_object_id, :biological_association_object_type, :biological_relationship_id]

  validate :biological_association_subject_type_is_allowed
  validate :biological_association_object_type_is_allowed

  attr_accessor :subject_global_id
  attr_accessor :object_global_id # TODO: this is badly named

  # TODO: Why?! this is just biological_association.biological_association_subject_type
  def subject_class_name
    biological_association_subject.try(:class).base_class.name
  end

  # TODO: Why?! this is just biological_association.biological_association_object_type
  def object_class_name
    biological_association_object.try(:class).base_class.name
  end

  def subject_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_subject_id, o.id)
    write_attribute(:biological_association_subject_type, o.metamorphosize.class.name)
  end

  def object_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_object_id, o.id)
    write_attribute(:biological_association_object_type, o.metamorphosize.class.name)
  end

  # @return [ActiveRecord::Relation]
   #def self.collection_objects_subject_join
   #  a = arel_table
   #  b = ::CollectionObject.arel_table
   #  j = a.join(b).on(a[:biological_association_subject_type].eq('CollectionObject').and(a[:biological_association_subject_id].eq(b[:id])))
   #  joins(j.join_sources)
   #end

  # @return [ActiveRecord::Relation]
  def self.targeted_join(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  # @return [ActiveRecord::Relation]
  def self.targeted_join2(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
  end

  # Not used
  # @return [ActiveRecord::Relation]
  def self.targeted_left_join(target: 'subject', target_class: ::Otu )
    a = arel_table
    b = target_class.arel_table

    j = a.join(b, Arel::Nodes::OuterJoin).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  private

  def biological_association_subject_type_is_allowed
    errors.add(:biological_association_subject_type, 'is not permitted') unless biological_association_subject && biological_association_subject.class.is_biologically_relatable?
  end

  def biological_association_object_type_is_allowed
    errors.add(:biological_association_object_type, 'is not permitted') unless biological_association_object && biological_association_object.class.is_biologically_relatable?
  end

end

#biological_association_subject_typeString

Returns Rails polymorphic, type fo the subject (e.g. Otu).

Returns:

  • (String)

    Rails polymorphic, type fo the subject (e.g. Otu)



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/biological_association.rb', line 29

class BiologicalAssociation < ApplicationRecord
  include Housekeeping
  include SoftValidation
  include Shared::Citations
  include Shared::Tags
  include Shared::Identifiers
  include Shared::DataAttributes
  include Shared::Confidences
  include Shared::Notes
  include Shared::Confidences
  include Shared::Depictions
  include Shared::IsData

  belongs_to :biological_relationship, inverse_of: :biological_associations

  has_many :subject_biological_relationship_types, through: :biological_relationship
  has_many :object_biological_relationship_types, through: :biological_relationship

  has_many :subject_biological_properties, through: :subject_biological_relationship_types, source: :biological_property
  has_many :object_biological_properties, through: :object_biological_relationship_types, source: :biological_property

  belongs_to :biological_association_subject, polymorphic: true
  belongs_to :biological_association_object, polymorphic: true
  has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_association, dependent: :destroy
  has_many :biological_associations_graphs, through: :biological_associations_biological_associations_graphs, inverse_of: :biological_associations

  validates :biological_relationship, presence: true
  validates :biological_association_subject, presence: true
  validates :biological_association_object, presence: true

  validates_uniqueness_of :biological_association_subject_id, scope: [:biological_association_subject_type, :biological_association_object_id, :biological_association_object_type, :biological_relationship_id]

  validate :biological_association_subject_type_is_allowed
  validate :biological_association_object_type_is_allowed

  attr_accessor :subject_global_id
  attr_accessor :object_global_id # TODO: this is badly named

  # TODO: Why?! this is just biological_association.biological_association_subject_type
  def subject_class_name
    biological_association_subject.try(:class).base_class.name
  end

  # TODO: Why?! this is just biological_association.biological_association_object_type
  def object_class_name
    biological_association_object.try(:class).base_class.name
  end

  def subject_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_subject_id, o.id)
    write_attribute(:biological_association_subject_type, o.metamorphosize.class.name)
  end

  def object_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_object_id, o.id)
    write_attribute(:biological_association_object_type, o.metamorphosize.class.name)
  end

  # @return [ActiveRecord::Relation]
   #def self.collection_objects_subject_join
   #  a = arel_table
   #  b = ::CollectionObject.arel_table
   #  j = a.join(b).on(a[:biological_association_subject_type].eq('CollectionObject').and(a[:biological_association_subject_id].eq(b[:id])))
   #  joins(j.join_sources)
   #end

  # @return [ActiveRecord::Relation]
  def self.targeted_join(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  # @return [ActiveRecord::Relation]
  def self.targeted_join2(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
  end

  # Not used
  # @return [ActiveRecord::Relation]
  def self.targeted_left_join(target: 'subject', target_class: ::Otu )
    a = arel_table
    b = target_class.arel_table

    j = a.join(b, Arel::Nodes::OuterJoin).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  private

  def biological_association_subject_type_is_allowed
    errors.add(:biological_association_subject_type, 'is not permitted') unless biological_association_subject && biological_association_subject.class.is_biologically_relatable?
  end

  def biological_association_object_type_is_allowed
    errors.add(:biological_association_object_type, 'is not permitted') unless biological_association_object && biological_association_object.class.is_biologically_relatable?
  end

end

#biological_relationship_idInteger

Returns the BiologicalRelationship id.

Returns:

  • (Integer)

    the BiologicalRelationship id



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/biological_association.rb', line 29

class BiologicalAssociation < ApplicationRecord
  include Housekeeping
  include SoftValidation
  include Shared::Citations
  include Shared::Tags
  include Shared::Identifiers
  include Shared::DataAttributes
  include Shared::Confidences
  include Shared::Notes
  include Shared::Confidences
  include Shared::Depictions
  include Shared::IsData

  belongs_to :biological_relationship, inverse_of: :biological_associations

  has_many :subject_biological_relationship_types, through: :biological_relationship
  has_many :object_biological_relationship_types, through: :biological_relationship

  has_many :subject_biological_properties, through: :subject_biological_relationship_types, source: :biological_property
  has_many :object_biological_properties, through: :object_biological_relationship_types, source: :biological_property

  belongs_to :biological_association_subject, polymorphic: true
  belongs_to :biological_association_object, polymorphic: true
  has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_association, dependent: :destroy
  has_many :biological_associations_graphs, through: :biological_associations_biological_associations_graphs, inverse_of: :biological_associations

  validates :biological_relationship, presence: true
  validates :biological_association_subject, presence: true
  validates :biological_association_object, presence: true

  validates_uniqueness_of :biological_association_subject_id, scope: [:biological_association_subject_type, :biological_association_object_id, :biological_association_object_type, :biological_relationship_id]

  validate :biological_association_subject_type_is_allowed
  validate :biological_association_object_type_is_allowed

  attr_accessor :subject_global_id
  attr_accessor :object_global_id # TODO: this is badly named

  # TODO: Why?! this is just biological_association.biological_association_subject_type
  def subject_class_name
    biological_association_subject.try(:class).base_class.name
  end

  # TODO: Why?! this is just biological_association.biological_association_object_type
  def object_class_name
    biological_association_object.try(:class).base_class.name
  end

  def subject_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_subject_id, o.id)
    write_attribute(:biological_association_subject_type, o.metamorphosize.class.name)
  end

  def object_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_object_id, o.id)
    write_attribute(:biological_association_object_type, o.metamorphosize.class.name)
  end

  # @return [ActiveRecord::Relation]
   #def self.collection_objects_subject_join
   #  a = arel_table
   #  b = ::CollectionObject.arel_table
   #  j = a.join(b).on(a[:biological_association_subject_type].eq('CollectionObject').and(a[:biological_association_subject_id].eq(b[:id])))
   #  joins(j.join_sources)
   #end

  # @return [ActiveRecord::Relation]
  def self.targeted_join(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  # @return [ActiveRecord::Relation]
  def self.targeted_join2(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
  end

  # Not used
  # @return [ActiveRecord::Relation]
  def self.targeted_left_join(target: 'subject', target_class: ::Otu )
    a = arel_table
    b = target_class.arel_table

    j = a.join(b, Arel::Nodes::OuterJoin).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  private

  def biological_association_subject_type_is_allowed
    errors.add(:biological_association_subject_type, 'is not permitted') unless biological_association_subject && biological_association_subject.class.is_biologically_relatable?
  end

  def biological_association_object_type_is_allowed
    errors.add(:biological_association_object_type, 'is not permitted') unless biological_association_object && biological_association_object.class.is_biologically_relatable?
  end

end

#object_global_idObject

TODO: this is badly named



65
66
67
# File 'app/models/biological_association.rb', line 65

def object_global_id
  @object_global_id
end

#project_idInteger

the project ID

Returns:

  • (Integer)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'app/models/biological_association.rb', line 29

class BiologicalAssociation < ApplicationRecord
  include Housekeeping
  include SoftValidation
  include Shared::Citations
  include Shared::Tags
  include Shared::Identifiers
  include Shared::DataAttributes
  include Shared::Confidences
  include Shared::Notes
  include Shared::Confidences
  include Shared::Depictions
  include Shared::IsData

  belongs_to :biological_relationship, inverse_of: :biological_associations

  has_many :subject_biological_relationship_types, through: :biological_relationship
  has_many :object_biological_relationship_types, through: :biological_relationship

  has_many :subject_biological_properties, through: :subject_biological_relationship_types, source: :biological_property
  has_many :object_biological_properties, through: :object_biological_relationship_types, source: :biological_property

  belongs_to :biological_association_subject, polymorphic: true
  belongs_to :biological_association_object, polymorphic: true
  has_many :biological_associations_biological_associations_graphs, inverse_of: :biological_association, dependent: :destroy
  has_many :biological_associations_graphs, through: :biological_associations_biological_associations_graphs, inverse_of: :biological_associations

  validates :biological_relationship, presence: true
  validates :biological_association_subject, presence: true
  validates :biological_association_object, presence: true

  validates_uniqueness_of :biological_association_subject_id, scope: [:biological_association_subject_type, :biological_association_object_id, :biological_association_object_type, :biological_relationship_id]

  validate :biological_association_subject_type_is_allowed
  validate :biological_association_object_type_is_allowed

  attr_accessor :subject_global_id
  attr_accessor :object_global_id # TODO: this is badly named

  # TODO: Why?! this is just biological_association.biological_association_subject_type
  def subject_class_name
    biological_association_subject.try(:class).base_class.name
  end

  # TODO: Why?! this is just biological_association.biological_association_object_type
  def object_class_name
    biological_association_object.try(:class).base_class.name
  end

  def subject_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_subject_id, o.id)
    write_attribute(:biological_association_subject_type, o.metamorphosize.class.name)
  end

  def object_global_id=(value)
    o = GlobalID::Locator.locate(value)
    write_attribute(:biological_association_object_id, o.id)
    write_attribute(:biological_association_object_type, o.metamorphosize.class.name)
  end

  # @return [ActiveRecord::Relation]
   #def self.collection_objects_subject_join
   #  a = arel_table
   #  b = ::CollectionObject.arel_table
   #  j = a.join(b).on(a[:biological_association_subject_type].eq('CollectionObject').and(a[:biological_association_subject_id].eq(b[:id])))
   #  joins(j.join_sources)
   #end

  # @return [ActiveRecord::Relation]
  def self.targeted_join(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  # @return [ActiveRecord::Relation]
  def self.targeted_join2(target: 'subject', target_class: ::Otu)
    a = arel_table
    b = target_class.arel_table

    j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
  end

  # Not used
  # @return [ActiveRecord::Relation]
  def self.targeted_left_join(target: 'subject', target_class: ::Otu )
    a = arel_table
    b = target_class.arel_table

    j = a.join(b, Arel::Nodes::OuterJoin).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
    joins(j.join_sources)
  end

  private

  def biological_association_subject_type_is_allowed
    errors.add(:biological_association_subject_type, 'is not permitted') unless biological_association_subject && biological_association_subject.class.is_biologically_relatable?
  end

  def biological_association_object_type_is_allowed
    errors.add(:biological_association_object_type, 'is not permitted') unless biological_association_object && biological_association_object.class.is_biologically_relatable?
  end

end

#subject_global_idObject

Returns the value of attribute subject_global_id.



64
65
66
# File 'app/models/biological_association.rb', line 64

def subject_global_id
  @subject_global_id
end

Class Method Details

.targeted_join(target: 'subject', target_class: ::Otu) ⇒ ActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


98
99
100
101
102
103
104
# File 'app/models/biological_association.rb', line 98

def self.targeted_join(target: 'subject', target_class: ::Otu)
  a = arel_table
  b = target_class.arel_table

  j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
  joins(j.join_sources)
end

.targeted_join2(target: 'subject', target_class: ::Otu) ⇒ ActiveRecord::Relation

Returns:

  • (ActiveRecord::Relation)


107
108
109
110
111
112
# File 'app/models/biological_association.rb', line 107

def self.targeted_join2(target: 'subject', target_class: ::Otu)
  a = arel_table
  b = target_class.arel_table

  j = a.join(b).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
end

.targeted_left_join(target: 'subject', target_class: ::Otu) ⇒ ActiveRecord::Relation

Not used

Returns:

  • (ActiveRecord::Relation)


116
117
118
119
120
121
122
# File 'app/models/biological_association.rb', line 116

def self.targeted_left_join(target: 'subject', target_class: ::Otu )
  a = arel_table
  b = target_class.arel_table

  j = a.join(b, Arel::Nodes::OuterJoin).on(a["biological_association_#{target}_type".to_sym].eq(target_class.name).and(a["biological_assoication_#{target}_id".to_sym].eq(b[:id])))
  joins(j.join_sources)
end

Instance Method Details

#biological_association_object_type_is_allowedObject (private)



130
131
132
# File 'app/models/biological_association.rb', line 130

def biological_association_object_type_is_allowed
  errors.add(:biological_association_object_type, 'is not permitted') unless biological_association_object && biological_association_object.class.is_biologically_relatable?
end

#biological_association_subject_type_is_allowedObject (private)



126
127
128
# File 'app/models/biological_association.rb', line 126

def biological_association_subject_type_is_allowed
  errors.add(:biological_association_subject_type, 'is not permitted') unless biological_association_subject && biological_association_subject.class.is_biologically_relatable?
end

#object_class_nameObject

TODO: Why?! this is just biological_association.biological_association_object_type



73
74
75
# File 'app/models/biological_association.rb', line 73

def object_class_name
  biological_association_object.try(:class).base_class.name
end

#subject_class_nameObject

TODO: Why?! this is just biological_association.biological_association_subject_type



68
69
70
# File 'app/models/biological_association.rb', line 68

def subject_class_name
  biological_association_subject.try(:class).base_class.name
end