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

Find or Create by ID #527

Closed
sqlninja opened this issue Jun 18, 2019 · 2 comments
Closed

Find or Create by ID #527

sqlninja opened this issue Jun 18, 2019 · 2 comments

Comments

@sqlninja
Copy link

So I have a "micro" twitter system I maintain, where we store profiles, tweets, favorites, and followers for users in our db.
We store them because we crunch a lot of data together and it's easier than calling the real twitter API every time.

I've noticed when trying to do a find_or_create_by on profiles that if I use the id for the profile it always attempts an update because of the ORM#new? method checking for an id.

I have a search that allows users to search for other Twitter users, and I then attempt to save the new twitter profile using the id, this ensures if a screen_name changes we still get who we were hoping for.

Any insight on the best way to handle this?

@sqlninja
Copy link
Author

I feel this can stem from this issue as well: #494

@zacharywelch
Copy link
Collaborator

Hi @sqlninja as you point out, this is a side effect of new? not knowing if the resource exists or not. The only workaround that comes to mind is calling save_existing when find or find_by returns nil. Let us know if that helps. Meanwhile I'm going to close this as a duplicate of #494.

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