2008/07/08

OneToOne relations in Elixir

Note that a OneToOne relationship cannot exist without a corresponding ManyToOne relationship in the other way. This is because the OneToOne relationship needs the foreign_key created by the ManyToOne relationship.
When an OneToOne relation is needed, you need to make ManyToOne relationship first, where in database foreign keys are stored.

Example:

class Movie(Entity):
using_options(tablename='Movie',autosetup=True)
title=Field(Unicode(30))
year=Field(Integer)
decription=Field(Unicode)
director=ManyToOne('Director')

class Director(Entity):
using_options(tablename='Director',autosetup=True)
name=Field(Unicode(60))
movie=OneToOne('Movie')

No comments: