Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

ref updates #81

Closed Jaymon closed 5 years ago

Jaymon commented 5 years ago

These are notes I had for the Query.ref updates I've made, I wasn't sure what to do with them but didn't want to just get rid of them so I"m putting them here

one_to_one - find the id in self.orm_class that matches orm_classpath and set it as orm_classpath.pk
many_to_one - don't set any values (this is the default)
one_to_many - find the id in orm_classpath that matches self.orm_class.pk and set it as orm_classpath.FOUND_ID

from, to
to, from
to

self, "Foo"
"Foo", self
"Foo"

10, "Foo" -> select * from Foo where _id=10
"Foo", 10 -> select * from Foo where field=10

orm, "Foo" -> select * from Foo where _id = orm.foo_field
"Foo", orm -> select * from Foo where field = orm.pk

ref(to, from)

ref("Foo") -> query with Foo.query (no params set
ref(to="Foo", from=o) -> Foo.query.is_pk(o.field).
ref(to=o, from="Foo") -> Foo.query.is_field(o.pk)

ref(to, value) -> reference to TO with TO.pk found in value
ref(from, value) -> reference from FROM with value pk in FROM.field