Hey Dan,

I've had no problems splitting TG models across multiple files in the
past. I generally set 'model' up as a package, so for your code above
I'd structure it like so:

    mmtest/
        create_tables.py
        model/
            __init__.py
            dog.py
            man.py

dog.py:
-------
    from elixir import Entity, Field, Unicode, ManyToOne

    class Dog(Entity):
        name = Field(Unicode(10))
        owner = ManyToOne('Man')
        def __repr__(self):
            return '<Dog \'%s\'>' % (self.name)

man.py:
-------
    from elixir import Entity, Field, Unicode, OneToMany

    class Man(Entity):
        name = Field(Unicode(10))
        pets = OneToMany('Dog')
        def __repr__(self):
            return '<Man \'%s\'>' % (self.name)

__init.py__:
------------
    from elixir import setup_all

    from dog import Dog
    from man import Man

    print "Man: %s" % Man.__metaclass__._entities
    print "Dog: %s" % Dog.__metaclass__._entities

create_tables.py:
-----------------
    from elixir import metadata, setup_all
    from model import *

    metadata.bind = "sqlite:///multifilemodel.db"

    setup_all(True)

Running create_tables.py gives me:

    Man: {20702984: {'Man': <class 'model.man.Man'>,
                     'Dog': <class 'model.dog.Dog'>,
                     'Entity': <class 'elixir.entity.Entity'>}}
    Dog: {20702984: {'Man': <class 'model.man.Man'>,
                     'Dog': <class 'model.dog.Dog'>,
                     'Entity': <class 'elixir.entity.Entity'>}}

And more pertinently:

    >sqlite3 multifilemodel.db
    SQLite version 3.5.7
    Enter ".help" for instructions
    sqlite> .schema
    CREATE TABLE model_dog_dog (
            id INTEGER NOT NULL,
            name VARCHAR(10),
            owner_id INTEGER,
            PRIMARY KEY (id),
             CONSTRAINT model_dog_dog_owner_id_fk FOREIGN
KEY(owner_id) REFERENCES model_man_man (id)
    );
    CREATE TABLE model_man_man (
            id INTEGER NOT NULL,
            name VARCHAR(10),
            PRIMARY KEY (id)
    );
    CREATE INDEX ix_model_dog_dog_owner_id ON model_dog_dog
(owner_id);

This is all tested & working under Elixir 0.5.1.

Hope this helps.

- alex23
--~--~---------~--~----~------------~-------~--~----~
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