I figured out what was going on and submitted it as a bug report:

https://github.com/datamapper/dm-validations/issues/24

While DM allows me to alias my legacy foreign keys as more readable accessors, 
and to use those aliased keys in :child_keys and :parent_key, dm-validations 
isn't following the same behaviour.  Oddly it does follow the behaviour when 
the model name matches the accessor name (in this case my #user accessor, which 
references a legacy key called `userid` works, but #subject, which also takes a 
user model but references the key `subjectid` does not work).

Excuse the noise anyway.


El 22/05/2011, a las 21:37, Chris Corbyn escribió:

> Hi Guys,
> 
> I'm at a bit of a roadblock as to whether I'm the one in the wrong, or DM is.
> 
> See my post on stackoverflow.com for the full version:
> 
> http://stackoverflow.com/questions/6087607/functional-test-with-datamapper-model-not-validating-when-it-should-be
> 
> In short, my functional test is failing, while when doing an manual test the 
> code does appear to work.
> 
> I was able to get it working by using my legacy field name in the params to 
> #new, which seems like a bug:
> 
> i.e.  instead of
> 
> def create
>   @user = User.get!(params[:user_id])
>   @note = AdminUserNote.new({
>     :user => active_user,
>     :subject => @user,
>     :content => params[:content]
>   });
>   if @note.save
>     redirect_to(admin_user_path(@user))
>   else
>     render :new
>   end
> end
> 
> I had to do:
> 
> def create
>   @user = User.get!(params[:user_id])
>   @note = AdminUserNote.new({
>     :user => active_user,
>     :subjectid => @user.id, # this is a horrible horrible hack
>     :content => params[:content]
>   });
>   if @note.save
>     redirect_to(admin_user_path(@user))
>   else
>     render :new
>   end
> end
> 
> Is this normal, or is it a bug?  I can't understand why the validation passes 
> in the development environment, but fails in the test environment.
> 
> Cheers,
> 
> Chris
> 

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to