zimbatm asked:

One to one relation ?

Tags: og late relate

Hi, I would like to do a one to one relation. With the following snippet, a relation oid is inserted on both sides. I would like only to have a host_oid in my config table. How should I do ?

class Host
  has_one Config
end

class Config
  belongs_to Host
end

(1 attempts)

leobm answered:

I think this is the correct form ?

require 'og'

def create
  Og.start
  Og.thread_safe=false
end

class HostConfig
end
  
class Host
  prop_accessor :name, String
  has_one HostConfig
end

class HostConfig
  prop_accessor :cfg, Hash
end

create

h = Host.new
h.host_config = HostConfig.create
h.save

because, you want add a config to the host. the result tables should look like:

oghost: oid, hostconfigoid

oghostconfig: oid

Rating: 0