关联的标签参考 [英] Label references for associations
本文介绍了关联的标签参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Rails为固定装置中的关联提供标签参考,例如:
Rails provides label references for associations in fixtures like this:
### in pirates.yml
reginald:
name: Reginald the Pirate
monkey: george
### in monkeys.yml
george:
name: George the Monkey
pirate: reginald
这对于未命名间隔的模型非常有用,但是我使用的是命名空间,因此Rails感到困惑,并希望插入标签而不是标签引用.
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
似乎是唯一的解决方案,虽然不是很漂亮,但比id更好.
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) %>
这篇关于关联的标签参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文