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?
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 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.
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?
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).