Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

including ActiveModel::Validations breaks DataMapper validations #4

Open
tillsc opened this issue Jan 2, 2015 · 1 comment
Open

Comments

@tillsc
Copy link

tillsc commented Jan 2, 2015

If a DataMapper model includes ActiveModel::Validations ActiveModel's implementation will override DataMapper's. This could happen for example by using ActiveModel::SecurePassword and has_secure_password for example when not disabling the included Validations with has_secure_password(:validations => false).

I'm not sure how it could be possible to implement a ActiveModel agnostic dm-validations when both dm-validations and ActiveModel are claiming the errors method for themselves.

Perhaps this gem could include ActiveModel::Validations in every DataMapper::Resource (causing .errors to return ActiveModel::Errors). The nice effect: You could use ActiveModel validators in your DataMapper model. The problem: AFAICS this would disable all DataMapper validations. I don't know if there is an elegant solution to delegate the error retrieval back to DataMapper.

@tpitale
Copy link
Member

tpitale commented Jan 2, 2015

Now that ActiveModel Validations exist in their current state, I have used them over dm validations in a number of cases. I generally think it wiser to choose one method over the other. In the case of using other AM functionality, that choice seems to be made for you :-/.

My 2 cents is that the code in DM validations might need to be pretty gnarly to dance around AM, when they're both trying to provide much of the same functionality. As you said errors is a huge conflict.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants