On Fri, Feb 22, 2008 at 11:34 PM, dundeemt <[EMAIL PROTECTED]> wrote:
>
> Ok, maybe I'm answering my own question -- but I have not idea if it
> is correct.
>
>
> class Addresses(Entity):
> using_options(tablename='addresses')
>
> custnmbr = ManyToOne('Customers', Unicode, primary_key=True)
>
> adrscode = Field(Unicode, primary_key=True)
> address1 = Field(Unicode)
>
>
> class Customers(Entity):
> using_options(tablename='customers')
>
> custnmbr = Field(Unicode, primary_key=True)
> custname = Field(Unicode)
> ...
> addresses = OneToMany('Addresses')
>
> elixir will successfully create the tables and relationships, but have
> I done what I was trying to do?
I think so.
> Specifically, is the forward relationship proper?
Sorry for the slow reply, but this seems fine EXCEPT for the ManyToOne
line, which should read:
custnmbr = ManyToOne('Customers', primary_key=True)
ie, you shouldn't specify it's type (Unicode) since it will
automatically take the type of the referenced column(s).
Hope it helps,
>
>
>
> On Feb 22, 3:23 pm, dundeemt <[EMAIL PROTECTED]> wrote:
> > I've been through the tutorial and I'm attempting to construct a 1-
> > Many relationship between Customers.custnmbr ~ Addresses.custnmbr
> >
> > Here is some sample code(no relations).
> >
> > class Addresses(Entity):
> > using_options(tablename='addresses')
> >
> > custnmbr = Field(Unicode, primary_key=True)
> > adrscode = Field(Unicode, primary_key=True)
> > address1 = Field(Unicode)
> > ...
> >
> > class Customers(Entity):
> > using_options(tablename='customers')
> >
> > custnmbr = Field(Unicode, primary_key=True)
> > custname = Field(Unicode)
> > ...
> >
> > The 1-Many forward relation would seem to be:
> > class Addresses(Entity):
> > using_options(tablename='addresses')
> >
> > custnmbr = Field(Unicode, primary_key=True)
> > adrscode = Field(Unicode, primary_key=True)
> > address1 = Field(Unicode)
> >
> > class Customers(Entity):
> > using_options(tablename='customers')
> >
> > custnmbr = Field(Unicode, primary_key=True)
> > custname = Field(Unicode)
> > addresses = OneToMany(Addresses)
> >
> > but I can't seem to figure out the back relationship that would be
> > needed. I apologize if this is already answered on the list but I
> > couldn't seem to find it -- probably wasn't searching for the correct
> > term. It's my first crack at ORM
> >
> > Jeff
> >
>
--
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
-~----------~----~----~----~------~----~------~--~---