Castle Active Record - 验证和关系
我有两个模型:foo 和 bar。 Foo 有一个 bar 对象。 Foo 和 bar 有验证规则。如果我调用 Foo.isValid() 它也不会验证 bar。我需要使用 isValid 验证栏。 Castle Active Record 验证如何用于关系?您有任何示例或文档吗?官方网站的文档很差,没有任何关于验证和关系的内容。 谢谢。
I have two models: foo and bar. Foo has a bar object. Foo and bar have validation rules. If I call Foo.isValid() it doesn't validate bar too. I need to validate bar with isValid. How does Castle Active Record Validation work for relationship? Do you have any example or documentation? The official site has a poor documentation and nothing about validations and relationships.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IIRC ActiveRecord 验证嵌套组件(即值类型),但不验证关系。
如果确实如此,则必须检查代理对象。如果它初始化代理对象,那将是相当灾难性的,可能会获取整个数据库。如果不这样做,那么它将破坏代理透明度,并且验证将在某种程度上不可预测或至少非常棘手。不管怎样,这很可能不是你想要的。但如果你真的知道自己在做什么,你可以 覆盖默认验证器。
IIRC ActiveRecord validates nested components (i.e. value types), but not relationships.
If it did, it would have to check for proxied objects. If it initialized proxied objects it would be pretty catastrophic, potentially fetching the entire database. If it didn't, then it would break proxy transparency, and validation would be somewhat unpredictable or at least very tricky. Either way, it's very probably not what you want. But if you really know what you're doing, you can override the default validator.