[Nitro] Og inheritance
Darrick W
darrickw at gmail.com
Thu Sep 14 00:00:01 EDT 2006
When I want to have a column that is essentially overridden like that,
I do something more like the following:
class A
property :foo, String
schema_inheritance
def bar=(v); end
def bar; nil; end
end
class B < A
property :bar_string, String
def bar=(v); self.bar_string = v; end
def bar; self.bar_string; end
end
class C < A
property :bar_int, Integer
def bar=(v); self.bar_int = v; end
def bar; self.bar_int; end
end
Technically, that behaviour could be generated from the schema you
gave, but Og currently isn't doing it. I'd love to hear whether
George is planning anything along those lines.
As for whether it's worthwhile, I think this is far better than
simulating the same thing on your own if your design calls for it.
Cheers,
Darrick
On 9/13/06, Jon A. Lambert <jlsysinc at alltel.net> wrote:
> Name collisions are a problem in OG inheritence.
>
> Example:
> -cut-
> require 'og'
>
> class A
> property :foo, String
> schema_inheritance
> end
> class B < A
> property :bar, String
> end
> class C < A
> property :bar, Integer
> end
>
> Og.setup(
> :destroy => true,
> :store => :psql,
> :user => 'zzzzzzzz',
> :password => 'zzzzzzzz',
> :name => 'test',
> :evolve_schema => true
> )
>
> test-# \d oga
> Table "public.oga"
> Column | Type | Modifiers
> --------+-----------------------+------------------------------------------------------
> ogtype | character varying(50) |
> foo | text |
> oid | integer | not null default
> nextval('public.oga_oid_seq'::text)
> bar | text |
> Indexes:
> "oga_pkey" primary key, btree (oid)
>
> -cut-
>
> I wonder if one is better off not using schema_inheritance and instead
> letting it create a table per class.
>
> What are the pros and cons?
>
> --
> J. Lambert
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>
More information about the Nitro-general
mailing list