# Loading fixtures

**URL:** <https://www.ruby-forum.com/t/loading-fixtures/139319>\
**Category:** Rails\
**Created:** [June 2, 2008, 10:17pm UTC](https://www.ruby-forum.com/t/loading-fixtures/139319 "2008-06-02T22:17:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 2, 2008, 10:17pm UTC](https://www.ruby-forum.com/t/loading-fixtures/139319/1 "2008-06-02T22:17:18Z")

</div>

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?

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

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 2, 2008, 11:26pm UTC](https://www.ruby-forum.com/t/loading-fixtures/139319/2 "2008-06-02T23:26:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 2, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/loading-fixtures/139319/3 "2008-06-02T23:59:05Z")

</div>

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
