Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with joins in an OO way without Class Creation #17

Open
Nick-Lucas opened this issue Jul 2, 2016 · 0 comments
Open

Deal with joins in an OO way without Class Creation #17

Nick-Lucas opened this issue Jul 2, 2016 · 0 comments

Comments

@Nick-Lucas
Copy link
Owner

Nick-Lucas commented Jul 2, 2016

Right now we can make multiple requests to the database and get related objects and code this into Bean subclasses, but one of Limebean's best features is you don't need these subclasses to do work. It might be nice to have an interface which can handled this for us, and allow CRUD operations on joins, without the need for table classes.

Conversely it might be totally overkill to do this as there are ways to achieve it already. But this would provide a common pattern to work with

A simple interface might look like:

Bean bean = api.Load("books", 7);
bean.Join("authors", foreignKeyField, joinKeyField);
List<Bean> authors = bean.Joins["authors"];
authors.foreach(a => api.Trash(author));

Or maybe with new objects to create and manage the join tree:

BeanPod pod = api.DispensePod("books")

// Single join on Book
pod.Join("authors", "author_id", "id")

// Chained join tree from Book
pod
  .Join("publishers", "publisher_id", "id")
  .Join("publisher_contacts", "id", "publisher_id")
  .Join("contacts", "contact_id", "id");

// Load an update
Bean book = pod.Load(7);
Bean contact = book
  .Joins["publishers"]  
  .Joins["publisher_contacts"]
  .Joins["contacts"]
  .FirstOrDefault(c => c.name == "Bob James");
if (contact != null) api.Trash(contact);

(.Joins[...] could lazy load as we need things, instead of eager loading entire trees)

@Nick-Lucas Nick-Lucas changed the title Deal with joins in an OO way Deal with joins in an OO way without Class Creation Jul 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant