I define some Entities which works fine; for meta programming issues. I now need to reflect the field properties defined in the model.
For example:
class Foo(Entity):
bar = OneToMany('Bar')
baz = ManyToMany('Baz')
Which type of relation is set: “ManyToMany”, “OneToMany” or even a plain “Field”, and the relation target?
Is there any simple way to reflect the Elixir Entities?
You can do introspection in Elixir as you would anywhere in Python — get all names of attributes of
class Foowithdir(Foo), extract an attribute given its name withgetattr(Foo, thename), check the type of the attribute withtype(theattr)orisinstance, etc. The string'Bar'that you pass as the attribute to the constructor of anyRelationshipsubclass (includingOneToManyandManyToMany) ends up as ther.of_kindattribute of the resulting instance r of the Relationship subclass.Module
inspectin the Python standard library may be a friendlier way to do introspection, but dir / getattr / isinstance &c are perfectly acceptable in many cases.