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

Hard to deal with repeated objects #8

Open
mlanett opened this issue Jun 30, 2015 · 2 comments
Open

Hard to deal with repeated objects #8

mlanett opened this issue Jun 30, 2015 · 2 comments

Comments

@mlanett
Copy link

mlanett commented Jun 30, 2015

I'm having some problems with objects when the relations form a graph.

Consider this:

Factory.define "author", Author, { name: "F. Scott Fitzgerald" }
Factory.define "book", Book, { title: "The Great Gatsby": author: Factory.get("author") }
Factory.define "contract", Contract, { author: Factory.get("author"), book: Factory.get("book") }

When we Factory.create("contract"), we fail because there will be two inserts of author; one by contract and one when it creates the relation for book. We should only have one author object and the same id in both places. This can be fixed by after() hooks but it's a mess.

But, for this following case we might expect that a relation is different each time.

Factory.define "person", Person, { name: Random.string }
Factory.define "dance", Pair, { leader: Factory.get("person"), follower: Factory.get("person") }

It's easy to fix the first case by putting a name:object cache in Factory.build and using it to ensure that relations created unique objects. But that would break the latter case. Is the latter case a reasonable expectation? If not then I can probably build the cache and make a PR. If so then we need to figure out the best way to accommodate it.

@mlanett
Copy link
Author

mlanett commented Jun 30, 2015

Also one may have a graph after calling multiple create methods, so exposing the cache optionally may also make sense.

@dburles
Copy link
Collaborator

dburles commented Jul 2, 2015

Hey @mlanett seems like a valid point, I wonder if such a feature has been implemented in similar packages?

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

No branches or pull requests

2 participants