From d515e5376343c5eedb5d5ef7f149519d765562ce Mon Sep 17 00:00:00 2001 From: Julian Cheal Date: Wed, 11 Jul 2018 13:05:44 +0100 Subject: [PATCH] [WIP] Adding flavor as a has one on VM I basically want to search Vms like `vms = Flavor.joins(:vms).where(:flavors => {:name => 't2.micro'})` so that in the api we can filter by flavor name --- app/models/vm_or_template.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/vm_or_template.rb b/app/models/vm_or_template.rb index fe80d1918010..a80312b4ebdf 100644 --- a/app/models/vm_or_template.rb +++ b/app/models/vm_or_template.rb @@ -60,6 +60,8 @@ class VmOrTemplate < ApplicationRecord has_one :miq_server, :foreign_key => :vm_id, :inverse_of => :vm + has_one :flavor, -> { where(:flavors => {:name => '?'}) }, :primary_key => :id, :inverse_of => :vm + has_one :operating_system, :dependent => :destroy has_one :hardware, :dependent => :destroy has_many :disks, :through => :hardware