los sensores tienen lecturas
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
f 2022-06-11 14:48:31 -03:00
parent 4271bd0347
commit d16947d1ba
4 changed files with 13 additions and 5 deletions

View file

@ -21,10 +21,10 @@ class ReadingsController < ActionController::API
params[:arduinos]&.reject do |a|
a[:id].blank? || a[:sensores].empty?
end&.each do |a|
arduino = reading.arduinos.find_or_initialize_by(local_id: a[:id])
arduino = raspberry.arduinos.find_or_initialize_by(local_id: a[:id])
a[:sensores].each do |s|
arduino.sensors.build(sensor_params s)
arduino.sensors.build(reading: reading, **sensor_params(s))
end
end

View file

@ -2,7 +2,6 @@
class Arduino < ApplicationRecord
belongs_to :raspberry
belongs_to :reading
has_many :sensors
validates_presence_of :local_id

View file

@ -2,8 +2,7 @@
class Reading < ApplicationRecord
belongs_to :raspberry
has_many :arduinos
has_many :sensors, through: :arduinos
has_many :sensors
# @param :public_key [SSHData::PublicKey]
def verify(public_key)

View file

@ -0,0 +1,10 @@
# frozen_string_literal: true
# XXX: La migración que deduplicaba Arduinos pierde la relación entre
# lectura y sensado.
class RemoveReadingToArduinoAssociation < ActiveRecord::Migration[6.1]
def change
add_belongs_to :sensors, :reading, index: true
remove_belongs_to :arduinos, :reading, index: true
end
end