Override/redefine a field of a parent entity

4 views
Skip to first unread message

AlexVhr

unread,
Jun 24, 2011, 8:47:36 AM6/24/11
to SQLElixir
Hi all!

I'm sorry if the answer to this situation was already given here, or
in the FAQ - I could not find it.

I've got this model set up:

class Document(EntityBase):

__metaclass__ = EntityMeta
doc_number = Field(Unicode(5),index=True)

class Order(Document):
pass

class Invoice(Document):
doc_number = Field(Unicode(10),index=True) #this type of
documents needs a longer number field

The result is:

"File "C:\Python27\Lib\site-packages\elixir-0.7.1-py2.7.egg\elixir
\entity.py", line 493, in add_column
(col.key, self.entity.__name__))
Exception: Column 'doc_number' already exist in 'Invoice' ! "

I know I could move 'doc_number' from inside the Document() and into
the Invoice() (and into Order() and so on...), but that kinda defeats
the encapsulation idea - Document() contains some common
functionality, that relies on 'doc_number' being present. Is there a
way around this? Thanks.

Andreas Kaiser

unread,
Jun 24, 2011, 3:33:57 PM6/24/11
to sqle...@googlegroups.com

Am 24.06.2011 um 14:47 schrieb AlexVhr:

> class Document(EntityBase):
>
> __metaclass__ = EntityMeta
> doc_number = Field(Unicode(5),index=True)
>
> class Order(Document):
> pass
>
> class Invoice(Document):
> doc_number = Field(Unicode(10),index=True) #this type of
> documents needs a longer number field
>
> The result is:
>
> "File "C:\Python27\Lib\site-packages\elixir-0.7.1-py2.7.egg\elixir
> \entity.py", line 493, in add_column
> (col.key, self.entity.__name__))
> Exception: Column 'doc_number' already exist in 'Invoice' ! "
>
> I know I could move 'doc_number' from inside the Document() and into
> the Invoice() (and into Order() and so on...), but that kinda defeats
> the encapsulation idea - Document() contains some common
> functionality, that relies on 'doc_number' being present. Is there a
> way around this?

"allowcoloverride" might be what you're looking for: http://elixir.ematia.de/apidocs/elixir.options.html


HTH,

Andreas

AlexVhr

unread,
Jun 24, 2011, 3:44:29 PM6/24/11
to SQLElixir
Thanks for the reply! However, it says 'Use with care as it is easy to
shoot oneself in the foot when overriding columns.' without clarifying
much about it. Any particular pitfalls I should be aware of? I'm a
complete Elixir\SQLA newbie.
Reply all
Reply to author
Forward
0 new messages