CircuitSacul/DetaORM

Is it possible to specify foreigh_key as in django?

Closed this issue · 1 comments

Hello! Is it possible to specify foreigh key as in django? or something similar, so that orm itself sends requests. Just use the handles to send another request... to make a model... Well, it 's dreary

class Role(Base, name="roles"):
  ...

class User(Base, name="users"):
  email: Field[str] = Field(default=None)
  username: Field[str] 
  registered_at: Field[int] = Field(default=int(time.mktime(datetime.now().timetuple())))
  role_key: Field[str] = ForeighKey(Role)

(cross-posting from Discord for future reference)

Since DetaBase doesn't support foreign keys, DetaORM won't either. Part of the reasoning is that a foreign key implies that the reference still exists, but this wouldn't be possible to achieve (efficiently) with DetaBASE.

Just store the key of the document in the base you want, and then fetch it explicitly:

class Role(Base, name="roles"):
  ...

class User(Base, name="users"):
  ...
  role_key: Field[str] = Field()

user: User = ...
role = await Role.get(user.role_key)