The following setup is partially working for me.

This is in a pylons project.

erp/model/user.py
--------------------------
from elixir import *

class User(Entity):
    using_options(tablename='users', autoload=True)

    preferences = OneToMany('Preference')


erp/model/pref.py
-------------------------
from elixir import *

class Preference(Entity):
    using_options(tablename='user_preferences', autoload=True)

    user = ManyToOne('User', colname='user_id')


erp/model/__init__.py
-------------------------------
from pylons import config
from elixir import *
metadata.bind = config['sqlalchemy.url']

from prefs import *
from users import *

setup_all()


The above setup works fine.  The trouble is when I add additional
imports
NEW erp/model/user.py
----------------------------------
from sets import Set  # <---- new line, only change.
from elixir import *

class User(Entity):
    using_options(tablename='users', autoload=True)

    preferences = OneToMany('Preference')


This setup works fine as well. The trouble starts when I add an
additional import.

NEW erp/model/user.py
----------------------------------
import datetime  # <---- new line, only change
from sets import Set
from elixir import *

class User(Entity):
    using_options(tablename='users', autoload=True)

    preferences = OneToMany('Preference')

With this change I get KeyError: 'Preference'. I have tried many
variations on what the
additional imports are (different modules, * vs explicit import, etc)
and the only pattern
that has emerged is I can't import more than one additional item other
than elixir.
(I have also tried importing elixir classes/functions explicitly)

anyone have any ideas?

-brad

On Apr 30, 9:27 pm, alex bodnaru <[EMAIL PROTECTED]> wrote:
> every class knows about classes defined in the same model, or in models 
> imported
> before it's definition.
>
> call setup_all at the end of the model that knows everything.
>
> i'll try your model hierarchy tomorrow, but i have my working hierarchy for 
> some
> time :) .
>
> best regards,
>
> alex
>
> DanL wrote:
> > So do you mean for, say, humans.py:
>
> > humans.py:
> > -----------
> > from elixir import Field, Unicode, OneToMany, Entity
> > from tgmultifilemodel.model import *
>
> > class Man(Entity):
>
> >     name = Field(Unicode(10))
> >     pets = OneToMany('Dog')
>
> >     def __repr__(self):
> >         return '<Man \'%s\'>' % (self.name)
>
> > This doesn't seem to work... it creates the key error I described
> > above.
>
> > -Dan
>
> > On Apr 30, 6:10 pm, alex bodnaru <[EMAIL PROTECTED]> wrote:
> >> to avoid unnatural full address, which will further complicate after each
> >> import, use from model import *.
>
> >> Gaetan de Menten wrote:
> >>> Yeah, that's the only reliable method currently. Thanks for digging in
> >>> the mailing list archive for the answer!
> >>> I've had an answer to DanL message in my draft folder for quite a
> >>> while now (no idea why I didn't send it when I wrote it :-/).
> >>> I'll definitely need to address this in a FAQ or even the tutorial
> >>> given the number of people who trip on this...
> >>> On Wed, Apr 30, 2008 at 10:56 AM, Yap Sok Ann <[EMAIL PROTECTED]> wrote:
> >>>>  On Apr 30, 11:32 am, Yap Sok Ann <[EMAIL PROTECTED]> wrote:
> >>>>  > The model below doesn't seem to work with any of the import methods
> >>>>  > laid out in this discussion and in the wiki. It has an "odd many-to-
> >>>>  > many relationship" which is modeled following Gaeten's suggestion 
> >>>> inhttp://www.mail-archive.com/[EMAIL PROTECTED]/msg02616.html
> >>>>  > man.py
> >>>>  > ------
> >>>>  > from elixir import Entity, Field, Unicode, has_many
> >>>>  > class Man(Entity):
> >>>>  >     name = Field(Unicode(10))
> >>>>  >     has_many('relationships', of_kind='Relationship')
> >>>>  >     def __repr__(self):
> >>>>  >         return '<Man \'%s\'>' % (self.name)
> >>>>  > woman.py
> >>>>  > --------
> >>>>  > from elixir import Entity, Field, Unicode, has_many
> >>>>  > class Woman(Entity):
> >>>>  >     name = Field(Unicode(10))
> >>>>  >     has_many('relationships', of_kind='Relationship')
> >>>>  >     def __repr__(self):
> >>>>  >         return '<Woman \'%s\'>' % (self.name)
> >>>>  > relationship.py
> >>>>  > ---------------
> >>>>  > from elixir import Entity, Field, Unicode, belongs_to
> >>>>  > class Relationship(Entity):
> >>>>  >     name = Field(Unicode(10))
> >>>>  >     belongs_to('man', of_kind='Man', required=True)
> >>>>  >     belongs_to('woman', of_kind='Woman', required=True)
> >>>>  >     def __repr__(self):
> >>>>  >         return '<Relationship \'%s\'>' % (self.name)
> >>>>  > Tested under Elixir 0.5.2
> >>>>  I got it to work using full path addressing as mentioned by Gaeten in
> >>>>  
> >>>> http://groups.google.com/group​/sqlelixir/browse_thread/thread​/bc8b23a1ae8bd9ec
> >>>>  Dan, can you try if it works for you? Should work fine regardless of
> >>>>  how to structure the files or where to do the import.
> >>>>  FWIW, here's what I have:
> >>>>  model/__init__.py
> >>>>  -----------------
> >>>>  model/man.py
> >>>> ------------
> >>>>  from elixir import Entity, Field, Unicode, has_many
> >>>>  c​lass Man(Entity):
> >>>>     name = Field(Unicode(10))
> >>>>     has_many('re​lationships', of_kind='model.relationship.Re
> >>>>  lationship')
> >>>>     has_many('women', through='relationships', via='woman')
> >>>>     def __repr__(self):
> >>>>         return '<Man \'%s\'>' % (self.name)
> >>>>  model/woman.py
> >>>> ------​--------
> >>>>  from elixir import Entity, Field, Unicode, has_many
> >>>>  class Woman(Entity):
> >>>>     name = Field(Unicode(10))
> >>>>     has_many('relationships',
> >>>>  of_kind='model.relationship.Relationship')
> >>>>     has_many('men', through='relationships', via='man')
> >>>>     def __repr__(self):
> >>>>         return '<Woman \'%s\'>' % (self.name)
> >>>>  model/relationship.py
> >>>> ---------------------
> >>>>  from elixir import Entity, Field, Unicode, belongs_to
> >>>>  class Relationship(Entity):
> >>>>     name = Field(Unicode(10))
> >>>>     belongs_to('man', of_kind='model.man.Man',
> >>>>  inverse='relationships', required=True)
> >>>>     belongs_to('woman', of_kind='model.woman.Woman',
> >>>>  inverse='relationships', required=True)
> >>>>     def __repr__(self):
> >>>>         return '<Relationship \'%s\'>' % (self.name)
> >>>>  test.py
> >>>>  -------
> >>>>  from elixir import Entity, setup_all
> >>>>  from model.man import Man
> >>>>  from model.woman import Woman
> >>>>  from model.relationship import Relationship
> >>>>  print Entity.__metaclass__._entities
> >>>>  setup_all()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to