Browse the Ruby on Rails Community.

You are here: Browse Railsplugins Awesome Fixtures

Awesome Fixtures

Rails extends the YAML model somewhat. Once you start building a complex application, managing interactions between data in separate fixture files becomes time-consuming and confusing. For example, maintaining the foreign-key IDs between associated models makes it difficult to add new records or understand existing data because you’re always looking up the IDs.

If your foreign keys and fixture data follow strict rails conventions, such as users.yml and (foreign key) user_id you can take advantage of named foreign keys by using the form, : :record_name

For example, when the format of users.yml is

joe: 
  id: 1
  name: Joe
mary: 
  id: 2
  name: Mary-Jane

..and the format of an associated table’s fixture file, say, houses.yml (where house belongs_to user)

joe_home:
  id: 1
  user: :joe
  name: Joe's Place
mary_home:
  id: 2
  user: :mary
  name: Mary In The Hizzle

Upon instantiation, the joe_home record will be automatically assigned a user_id of 1, and the mary_home record will be assigned user_id 2. These IDs are automatically filled out for you.

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all details


Membership

+ Join this railsplugin

Record Maintainer

'None'