Skip to content

Feature/primary keys #112

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

Closed
wants to merge 5 commits into from
Closed

Conversation

D1plo1d
Copy link

@D1plo1d D1plo1d commented Jul 4, 2014

Adding a :primary_key option to closure tree. This allows closure tree to reference models in the tree by a different column then their default primary key.

Useful when dealing with models which have both and id and a uuid and the closure tree needs to be built off the uuids.

@mceachen
Copy link
Collaborator

mceachen commented Jul 4, 2014

Thanks for the PR, I'll review it asap.

Out of curiosity, when would you want two unique identifiers for a table?

Or is this to support a legacy table design?

@D1plo1d
Copy link
Author

D1plo1d commented Jul 4, 2014

@mceachen The uuids are generated on an ios app that synchronize their data with the server when they can. So I use accepts_nested_attributes to save the models + hierarchy data. Because I'm saving the models all at once I don't have access to a parent's id until after all the models are saved. So I used uuids w/ closure trees to reduce the number of SQL interactions I needed to save the models.

The auto increment id primary key is just to leave my options open so that I can speed up non-closure_tree lookups later on as need be (because it's less bytes per key and there will be less empty space between keys in the keyspace).

@D1plo1d
Copy link
Author

D1plo1d commented Jul 4, 2014

Hmm, this seems to have broken a lot of unit tests. Unfortunately I don't have mysql on my machine. This is a bit of a problem..

@mceachen
Copy link
Collaborator

mceachen commented Jul 4, 2014

If you can get the tests to pass, and add a model in the tests that exercise this, I'm happy to merge it.

@D1plo1d
Copy link
Author

D1plo1d commented Jul 7, 2014

I added unit tests for the primary key feature and fixed all the errors I was seeing when I ran rspec.

However when I run tests.sh I'm seeing a bunch more issues which I'm less certain about.

In particular I'm getting "time interval must be positive" from parallel_spec.rb:10:. And recursive locking errors from database_cleaner.rb:6. It doesn't seem like this is related to the changes in my pull request though and I'm not really sure of their cause.

@mceachen Thoughts?

@mceachen
Copy link
Collaborator

mceachen commented Dec 9, 2016

Please re-open when conflicts have been resolved and all tests pass.

@mceachen mceachen closed this Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants