Module: Shared::BiologicalAssociations
- Extended by:
- ActiveSupport::Concern
- Included in:
- Otu
- Defined in:
- app/models/concerns/shared/biological_associations.rb
Overview
Shared code for extending data classes with an OriginRelationship
How to use this concern:
1) In BOTH related models, Include this concern (`include Shared::OriginRelationship`)
2) In the "old" model call "is_origin_for" with valid class names, as strings, e.g.:
`is_origin_for 'CollectionObject', 'CollectionObject::BiologicalCollectionObject'`
3) has_many :derived_<foo> associations are created for each is_origin_for()
!! You must redundantly provide STI subclasses and parent classes if you want to allow both. Providing
a superclass does *not* provide the subclasses.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#all_biological_associations ⇒ Array
!! If self relationships are ever made possible this needs a DISTINCT clause.
Instance Method Details
#all_biological_associations ⇒ Array
!! If self relationships are ever made possible this needs a DISTINCT clause
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/concerns/shared/biological_associations.rb', line 35 def all_biological_associations BiologicalAssociation.find_by_sql( "SELECT biological_associations.* FROM biological_associations WHERE biological_associations.biological_association_subject_id = #{id} AND biological_associations.biological_association_subject_type = '#{self.class.base_class.name}' UNION SELECT biological_associations.* FROM biological_associations WHERE biological_associations.biological_association_object_id = #{id} AND biological_associations.biological_association_object_type = '#{self.class.base_class.name}'") end |