Accessing a model from a migration

Hello again!

ok, i have some initial migration code which sets up my apps schema. i
have a
few tables that get initialized with data in this migration where i have
table data in yaml format in test/fixtures. i use db:fixtures:load
FIXTURES=countries,provstates,employees to initialize these tables…

here’s the wrinkle: employees when it gets loaded should only contain
the admin
account (so i can access the app after running the migration)… however
employees.yml also contains some other accounts of various priveleges
testing purposes. what i want to do is load the fixture into the db, but
all the records except for the admin account… if i do:

cmd = ‘rake db:fixtures:load FIXTURES=countries,provstates,employees’
system cmd
Employee.delete_all “username != ‘admin’”

I get an error on the line that uses the Employee model. i tried a few
variations of require’ing the model, but haven’t had any luck…

my short term solution was to just have the admin account in the
fixture, but
now when i want to test i don’t have those other accounts to test with…

i’m pretty sure i could use ActiveRecord::Base to do this with a little
bit of
digging, but if i could use the model directly it would be much

thanks a bunch !


google search “rails using models in migrations”

1st hit:

Not trying to be snarky Stuart, it’s just that we don’t always
realize the power of the tools we have at hand. It’s sometimes easier
to ask - but the community benefits as a whole when we’re all more
powerful information users. (something about “teaching to fish”)


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs