On 9/8/07, Adam Gomaa <[EMAIL PROTECTED]> wrote:

> I'm putting together my first 'real' project with the assignment
> syntax, and with SQLAlchemy 0.4 no less, but so far everything is
> working, a few DeprecationWarnings notwithstanding.

I'm trying to slowly work through them. I hope that 0.4 will be
"deprecated warning"-free.

> Overall I'm doing well and greatly preferring this to writing the
> SQLAlchemy code by hand, but I've found the following somewhat
> unintuitive:

>     class Parent(Entity):
>         child = OneToOne("Child", inverse="parent")
>
>     class Child(Entity):
>         parent = ManyToOne("Parent", inverse="parent")

> Since what I want is a one-to-one on each field, it made more sense to
> me that I'd define OneToOne on each field, rather than a OneToOne and
> then a ManyToOne.

The catch is that in a OneToOne situation you still need a column
holding a foreign key to the related table, and if you use two
OneToOne relationships, there is nothing telling you (or Elixir) which
side has that column. So this is basically a syntax question, not a
technical issue.

We could do something like:

     class Parent(Entity):
         child = OneToOne("Child")

     class Child(Entity):
         parent = OneToOne("Parent", foreign_key=True)

Note that I don't think foreign_key is a good idea because it collides
with an SQLAlchemy argument, so if you can come up with a better
argument, that'd be good.

> Another thing to consider is a syntax like the following:
>
>     class Parent(Entity):
>         child = OneToOne("Child", inverse="parent")
>
>     class Child(Entity):
>         pass

In Elixir, you can do both: you can either declare each side of the
relationship on its class (and I'd recommend this because that way,
you can immediately know what attributes has a class, by just looking
at it), or declare both sides at once, by using a backref.

     class Parent(Entity):
         child = ManyToOne("Child", backref=backref("parent", uselist=False))

     class Child(Entity):
         pass

> Two more things: First, I get things more figured out I'd be happy to
> work on some documentation,

That's great news.

> and second, how do I go about getting a
> Trac account?

Before you get a real account, you can use guest/guest to edit the
wiki or post tickets.
-- 
Gaƫtan de Menten
http://openhex.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
-~----------~----~----~----~------~----~------~--~---

Reply via email to