开发者

Label references for associations

开发者 https://www.devze.com 2023-03-21 17:58 出处:网络
Rails provides label references for associations in fixtures like this: ### in pirates.yml reginald: name: Reginald the Pirate

Rails provides label references for associations in fixtures like this:

### in pirates.yml

  reginald:
    name: Reginald the Pirate
    monkey: george

### in开发者_JAVA百科 monkeys.yml

  george:
    name: George the Monkey
    pirate: reginald

This works great for not-namedspaced models, but I'm using namespaces, and so Rails gets confused, and want to insert the labels instead of the label references.

Any workaround or fix known?


Fixtures.identify seems to be the only solution, not really beautiful but better than ids.

### in pirates.yml

  reginald:
    name: Reginald the Pirate
    monkey_id: <%= Fixtures.identify(:george) %>


### in monkeys.yml

  george:
    name: George the Monkey
    pirate_id: <%= Fixtures.identify(:reginald) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消