los sensores tienen lecturas
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
4271bd0347
commit
d16947d1ba
4 changed files with 13 additions and 5 deletions
|
@ -21,10 +21,10 @@ class ReadingsController < ActionController::API
|
||||||
params[:arduinos]&.reject do |a|
|
params[:arduinos]&.reject do |a|
|
||||||
a[:id].blank? || a[:sensores].empty?
|
a[:id].blank? || a[:sensores].empty?
|
||||||
end&.each do |a|
|
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|
|
a[:sensores].each do |s|
|
||||||
arduino.sensors.build(sensor_params s)
|
arduino.sensors.build(reading: reading, **sensor_params(s))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
class Arduino < ApplicationRecord
|
class Arduino < ApplicationRecord
|
||||||
belongs_to :raspberry
|
belongs_to :raspberry
|
||||||
belongs_to :reading
|
|
||||||
has_many :sensors
|
has_many :sensors
|
||||||
|
|
||||||
validates_presence_of :local_id
|
validates_presence_of :local_id
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
class Reading < ApplicationRecord
|
class Reading < ApplicationRecord
|
||||||
belongs_to :raspberry
|
belongs_to :raspberry
|
||||||
has_many :arduinos
|
has_many :sensors
|
||||||
has_many :sensors, through: :arduinos
|
|
||||||
|
|
||||||
# @param :public_key [SSHData::PublicKey]
|
# @param :public_key [SSHData::PublicKey]
|
||||||
def verify(public_key)
|
def verify(public_key)
|
||||||
|
|
|
@ -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
|
Loading…
Reference in a new issue