Skip to content
This repository has been archived by the owner on Aug 27, 2023. It is now read-only.

Cross-table linking #2

Open
stevearc opened this issue Jan 31, 2014 · 3 comments
Open

Cross-table linking #2

stevearc opened this issue Jan 31, 2014 · 3 comments

Comments

@stevearc
Copy link
Owner

Some way to have models reference models. One-to-one, one-to-many, and many-to-many should be supported.

Since we don't have the benefit of a SQL database, we'll have to consider the following:

  • Save and sync actions should probably not propagate
  • Backrefs are possible, but...hard. Maybe add those later?
  • Query/model option to eager-load referenced models
  • What happens if a value is set but the object doesn't exist in the DB? None? AttributeError?
@xuru
Copy link

xuru commented Dec 20, 2016

Hi steven! Has there been any progress in this area? I've been using this library for a while now, and am pretty happy with it. Thanks for taking the time to write it!

To get the conversation started, how about we consider something like this:

class RefType(TypeDefinition):
    type = dict
    aliases = ['ref'] # alternate names that reference this type
    ddb_data_type = MAP

    def coerce(self, value, force):
        # How do we type check a model?  issubclass(value, Model)?
        return value

    def ddb_dump(self, value):
        # Somehow get the parent model's key
        return self.model.meta_.pk_dict(results[-1], ddb_dump=True)

    def ddb_load(self, value):
        return engine.get(self.model, **value)

We probably want to do something with Field... perhaps derive a RefField? in order to hide a lot of this.

Anyway, this is just off the top of my head ATM. I know I'm already running into this in my own project, and I have to run through a chain of queries (saving off only the hash_key). Would be nice to use some of the optimizations like batched queries, etc...

@xuru
Copy link

xuru commented Jan 16, 2017

I have the start of a Reference field located here. @stevearc I could really use your help with the caching. I have unittests that shows what I'm having trouble with. Any help would be most appreciated!

@xuru
Copy link

xuru commented Jan 17, 2017

@stevearc or anyone else that is interested... I now have a working Reference field that correctly loads, saves and deletes (including cascading deletes) located here. It would be really nice if I could get some peer review, and perhaps move it into the core library, but for now it should work as stand alone package.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants