Use fixtures within fixtures?

Heya,

I'm using globalize2 and have following problem with my fixtures:

categories.yml: one:   parent_id: two   color: #ff00aa

two:   color: #00ff11

three:   parent_id: two   color: #ab00ab

category_translations.yml one-en:   id: one   locale: en   name: Cars

one-es:   id: one   locale: es   name: Coches

two-en:   id: two   locale: en   name: Start

two-es:   id: two   locale: es   name: Inicio

three-en:   id: three   locale: en   name: Bicycles

three-es:   id: three   locale: es   name: Bicicletas

My problem now is that in my translations table all id's are NULL which is kinda obvious cause the fixture has no idea where one, two and three is. Does anyone know how to load a fixture inside a fixture in order to use them?

How about using erb?

<%= find_by_id(<some-id>) %>

Harold wrote:

How about using erb?

<%= find_by_id(<some-id>) %>

On Mar 28, 1:41�pm, Heinz Strunk <rails-mailing-l...@andreas-s.net>

First of all: I don't know the id because it's set randomly :slight_smile: I could set it in the other yml and then just use them but I'd actually prefer using rails generated ids. I could use find_by_whatever but I'd like to use fixtures only if possible.

Heinz Strunk wrote:

categories.yml: one:   parent_id: two   color: #ff00aa

one's raw ID is a hash of its identifier. Get it with

  <%= Fixture.identify(:one) %>

two:   color: #00ff11

three:   parent_id: two

That should be parent: two

Only use Fixture.identify() if you can't link up the real identifier, through either belongs_to or has_and_belongs_to_many. The point is to allow the Fixture system to install one database table by reading the minimum possible of its associated model, and by reading no other model or fixture file.

If globalize2 can't track these associations, you must use either Fixture.identify(), or you must fall back to old-fashioned Rails 1 fixtures, where everything has an id: with a hand-coded number in it...

Um well... I use two different yml-files so it doesn't find the identifiers from the other files. How do I tell him to look in the other one?

I don't get that...it doesn't really look at any other yml, it just calculates a hash:

Fixtures.identify(:one)

=> 953125641

Fixtures.identify(:two)

=> 996332877

How are you calling this?

-H

Um well... I use two different yml-files so it doesn't find the identifiers from the other files. How do I tell him to look in the other one?

It doesn't need to - the value of Fixture.identify(foo) depends only on foo itself (that's the whole point: being able to predict what id a fixture with a given label will have).

Fred

The finder call to the DB is redundant. How about you save yourself the trip to the db and just do

one-en: id: <%= Fixtures.identify(:one) -%> locale: en name: cars

Alright, it's working now. Thanks guys!