Thanks for the thorough explanation. Yeah, I had a bit of trouble
understanding the docs after a certain point.
How hard would it be to use a mix of SQLAlchemy and Elixir together at
the same time? I realize Elixir is just an abstraction layer for
SQLAlchemy, but when I've tried to get the two to work together, I've
not gotten very far. For example, in a function where SQLAlchemy would
expect a Table object, I'd try providing an Entity, or Entity.table,
and it wouldn't work.
-J
On Tue, Jun 3, 2008 at 9:28 AM, Jonathan LaCour
<[EMAIL PROTECTED]> wrote:
>
> Jason Porath wrote:
>
>> I think a lot of my hesitation in this comes from worrying that
>> Elixir will start messing around with the table structure. I'm
>> still a little shaky as to what's going on under the hood, and
>> when it will execute certain commands. A lot of what I'm having to
>> do is bridge several tables at the same time, so I don't know how
>> elixir would, say, commit that data, if the class I've given it
>> isn't a 1-to-1 matchup with the table. Would it add any fields not
>> in the table?
>
> This is a big deficiency of Elixir right now, in that we don't
> really document what is going on under the hood very well. And,
> to answer your question, you really need to get the mappings 100%
> perfect against your existing schema, or you are asking for trouble.
> You can see what Elixir has generated by looking at the entity's
> table object, which Elixir generates for you:
>
> from elixir import *
>
> class Person(Entity):
> name = Field(String(32))
> pets = OneToMany('Pet')
> using_options(tablename='people')
>
> class Pet(Entity):
> name = Field(String(32))
> owner = ManyToOne('Person')
> using_options(tablename='pets')
>
> setup_all()
>
> # print out a representation of the table
> # for the Person entity
> print repr(Person.table)
>
> # print out a representation of the table
> # for the Pet entity
> print repr(Pet.table)
>
>
> The main things that Elixir will do to your schema behind the
> scenes:
>
> 1. If you don't specify a primary key on your entity by passing
> the `primary_key` keyword argument to one or more `Field`s on
> your entity, one will be generated called `id`. To get around
> this, simply specify the primary key using the aforementioned
> keyword argument.
>
> 2. When you specify a `ManyToOne` relationship, this side of the
> relationship will generate a foreign key field to the primary key
> of the referenced entity automatically. You can read a bit more
> about this in our documentation:
>
> http://elixir.ematia.de/apidocs/elixir.relationships.html
>
> Note that you can specify an alternate column name.
>
> There are a few more things, such as entire tables being created
> when you use `ManyToMany`, which I do not recommend (use an
> association object instead). But these two are the big ones that you
> need to know when you get started.
>
> If you have a schema already in place and have a lot of trouble
> mapping your tables appropriately, you might be better off using
> plain SQLAlchemy. Elixir is great if you are starting fresh, but
> might not be the best fit for you if you have an existing schema
> which may not lend itself to Elixir's assumptions and design.
>
> That being said, SQLAlchemy itself is designed specifically to
> handle any schema you that throw at it. Its not quite as pretty, but
> it sure is functional! I have projects that use Elixir, and other
> projects that use plain-SQLAlchemy, depending on what ends up being
> the best fit.
>
> Best of luck.
>
> --
> Jonathan LaCour
> http://cleverdevil.org
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---