Loading fixtures

I have a role based access control system with models Right, Role and
User and there are 2 join tables… rights_roles and roles_users

I have been maintaining the Right & Role data via migrations which has
created a few duplications over time and a few omissions and I’m finding
that there is a variation between my testing_db and my development_db in
the rights and rights_roles tables as well.

So I’m thinking that I can maintain just one set of fixtures for rights
and rights_users and load them into whichever db I need.

So my first questions…

  1. How do I delete records from join table without id column?

    from script/console test

RightsRoles.destroy_all
ActiveRecord::StatementInvalid: PGError: ERROR: column “id” does not
exist
: DELETE FROM rights_roles
WHERE “id” = NULL

  1. If I have new fixtures to load for just these 2 tables (rights.yml
    and rights_roles.yml), how can I load them in the console?

Craig

On Mon, 2008-06-02 at 13:16 -0700, Craig W. wrote:

        WHERE "id" = NULL
  1. If I have new fixtures to load for just these 2 tables (rights.yml
    and rights_roles.yml), how can I load them in the console?

OK…I guess I can drop and recreate the table for the first question
but the second one puzzles me…how do I load a fixtures file from the
console?

Craig

On Mon, 2008-06-02 at 13:16 -0700, Craig W. wrote:

        WHERE "id" = NULL
  1. If I have new fixtures to load for just these 2 tables (rights.yml
    and rights_roles.yml), how can I load them in the console?

since I asked, I might as well provide the answers to my question…

  1. @rights = Right.find(:all)
    for right in @rights
    RightsRoles.destroy_all( “right_id” == right.id )
    right.destroy
    end

  2. require ‘active_record/fixtures’
    directory = File.join(File.dirname(FILE), “test/fixtures”)
    Fixtures.create_fixtures(directory, “rights”)
     Fixtures.create_fixtures(directory, “rights_roles”)

Craig