# Using the newly created value in faker gem

**URL:** <https://www.ruby-forum.com/t/using-the-newly-created-value-in-faker-gem/187788>\
**Category:** Rails\
**Created:** [April 29, 2010, 8:34am UTC](https://www.ruby-forum.com/t/using-the-newly-created-value-in-faker-gem/187788 "2010-04-29T08:34:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjayarun07](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/74df32/32.png) [@sanjayarun07](https://www.ruby-forum.com/u/sanjayarun07)\
**Post date:** [April 29, 2010, 8:34am UTC](https://www.ruby-forum.com/t/using-the-newly-created-value-in-faker-gem/187788/1 "2010-04-29T08:34:30Z")

</div>

require ‘faker’  
require ‘populator’  
require ‘date’

Dbase.destroy\_all  
User.destroy\_all  
Table.destroy\_all

100.times do  
u = User.new  
u.username = Faker::Internet.user\_name  
u.email = Faker::Internet.email  
u.password = “test”  
u.password\_confirmation = “test”  
u.save  
end  
I am using the Faker gem to load sample data in my app. I have three  
models, user, dbase and table.  
The table gets created under every dbase so I want it’s column ‘dbase’  
tp have the same value as the dbase.name that was created above.  
Please see the code :

10.times do  
u = User.find(id = rand(User.count))  
db = Dbase.new  
db.name = Faker::Company.name  
db.vendor = Faker::Company.name  
db.location = [ Faker::Address.city ,  
Faker::Address.us\_state\_abbr ].join(’.’)  
db.port = 50000  
db.defuser = u.username  
t1 = Faker::Company.name  
Table.populate(rand(10)) do |tab|  
tab.schema\_name = t1  
tab.tab\_name = Faker::Company.name

```
  tab.dbase = db.name #here it says undefined method `db' for

```

main:Object.

```
  tab.created_by = Faker::Name.name
  tab.created_on = Date.today.to_s
  tab.logged = rand(2)
end
db.save

```

end

I can accompolish the same using rails console so I am assuming the  
console holds the value in cache while this doesn’t commit or  
something.

Can anyone help on how to accomplish this?
