Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4612

Best way to return recently created object in ActiveRecord?

$
0
0

I'm creating an object that when called it will create an database record and I want this function to return the newly created object. This is what I got:

data = {foo: 'foo', bar: 'bar'}Dummy.new(data).save! # trueDummy.last # newest record in the database

I'm concerned about what this would mean when there are more than one sessions on the same database. Is there a sure-fire way of getting the record I just created?


Viewing all articles
Browse latest Browse all 4612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>