ponyorm / pony

Pony Object Relational Mapper
Apache License 2.0
3.65k stars 245 forks source link

Polymorphic relationships #649

Closed nburns closed 2 years ago

nburns commented 2 years ago

I'd like to be able to model a polymorphic relationship with pony, by specifying a object_id (the id of a record) and object_type (name of the table or python class), but I couldn't find anything in the docs to support this

similarly to how rails does it: https://guides.rubyonrails.org/association_basics.html#polymorphic-associations Screen Shot 2022-05-23 at 4 41 29 PM

Several searches for something like this in the docs came up empty (ex: https://duckduckgo.com/?q=poly+site%3A+https%3A%2F%2Fdocs.ponyorm.org) , I was wondering if this is something that's possible or if I'm missing something (also checked github for other questions and didn't see anything)

nburns commented 2 years ago

recreating this manually with a record_id and record_class column, then a method on the containing model like

def record(self):
  return locals()['self.record_class'].get(id=record_id)