Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metadatable type in poly_metadata relationship on Well #4582

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/models/well.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@
has_many :target_well_links, -> { stock }, class_name: 'Well::Link', foreign_key: :source_well_id
has_many :target_wells, through: :target_well_links, source: :target_well

# Can have many key value pairs of metadata
has_many :poly_metadata, as: :metadatable, dependent: :destroy

# Returns a collection of PolyMetadatum records associated with the Well.
# This method overrides the autogenerated poly_metadata method to pick the
# correct metadatable_type instead of the parent type. Without this override,
# the generated SQL uses the wrong class name, e.g. Receptacle instead of Well.
#
# @return [ActiveRecord::Relation] a collection of PolyMetadatum records
def poly_metadata
PolyMetadatum.where(metadatable_id: id, metadatable_type: self.class.name)

Check warning on line 61 in app/models/well.rb

View check run for this annotation

Codecov / codecov/patch

app/models/well.rb#L61

Added line #L61 was not covered by tests
end

belongs_to :plate, foreign_key: :labware_id
has_one :well_attribute, inverse_of: :well

Expand Down
2 changes: 2 additions & 0 deletions app/resources/api/v2/well_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class WellResource < BaseResource
# Attributes
attribute :position, readonly: true

has_many :poly_metadata, as: :metadatable, class_name: 'PolyMetadatum'

def position
{ 'name' => _model.map_description }
end
Expand Down
Loading