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

Add option for forcing record creation #53

Open
ltk opened this issue Jan 20, 2015 · 3 comments
Open

Add option for forcing record creation #53

ltk opened this issue Jan 20, 2015 · 3 comments

Comments

@ltk
Copy link
Contributor

ltk commented Jan 20, 2015

Per request by @mikesmayer

Is there anyway to force creation of a record?

I'm using a friendship/reverse-friendship model to create two way associations between objects. When sprig creates a seed record that is in a state of blocked, the system throws the expected message preventing the creation of the reverse-friendship that should also be marked blocked.

In my former seed file, I used an ! exclamation point to force the creation of the two friendships like so:

Peerpartnership.request(seed_consultantaccount, person8).block!
@mikesmayer
Copy link

@ltk I understand that Sprig might have risen from a need on a social networking-like project, is it possible to find out how the team dealt with forcing the creation of records? Presumably the system involved rules that included blocking, etc

@ltk
Copy link
Contributor Author

ltk commented Jan 20, 2015

Permissions in that project relied on state within records, not really with preventing the creation of records, so we've never encountered this need. But my recommendation for dealing with unconventional circumstances is to use Sprig to insert your records as close to their final intended state, and then manipulate them following the call to Sprig in your seed file. This is one advantage of Sprig not hijacking the db:seed Rake task. You still have a Ruby file where you can do whatever you need.

db/seeds/development.rb

sprig [Staffer]

Staffer.find_by_name('Evil').block!

@mikesmayer
Copy link

thanks! good work around

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

2 participants