On Fri, Jun 13, 2008 at 6:20 AM, Harish <[EMAIL PROTECTED]> wrote:
> I just started learning Elixir, and I am loving it. I would like to
> know how to handle Self Referencing Foreign Key relationship
> constraints in Elixir.
>
> For example : Employee has employee_id and name. Each employee has a
> supervisor, who is also an employee. The Employee at the highest level
> in the Hierarchy will have himself as his supervisor.
It might be easier to just say that this employee has no supervisor.
> Each supervisor can have many employees.
>
> How would the example model file look? Thanks for the help.
Self referencing relationships are defined just the same way as other
relationships.
So your example could be written like this:
class Employee(Entity):
name = Field(String(32))
supervisor = ManyToOne('Employee')
# and optionally
employees = OneToMany('Employee')
See
http://elixir.ematia.de/trac/browser/elixir/trunk/tests/test_o2m.py
for more examples...
You could also use a specific class for the supervisors, inheriting
from the Employee class, so that the employees (subordinates)
relationship is only present in that class.
--
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
-~----------~----~----~----~------~----~------~--~---