-
Notifications
You must be signed in to change notification settings - Fork 80
dm-types Flag fails to persist values assigned with the left shift operator. #26
Comments
This raises a larger issue about how to handle methods on attributes which modify the receiver therefore bypassing dirty tracking. 3 approaches to handle this:
I like approach 3. A simple fix that works across all kinds of properties and works with dirty tracking. It also makes it hard to accidentally change an attribute without reassigning it. by Carl Porth |
For example, you could do: by Carl Porth |
I see your reason for supporting approach 3, but it seems an unusual restriction to set (perhaps I’m uninformed). However, if the behavior is atypical, then it sort of presents a usability issue. Because the Flag type contains multiple values, and is represented as an array, it seems logical that I can push things into it. One of the reasons I appreciate DataMapper is that it does feel like "All Ruby All The Time", and things work naturally. I think this is especially important if #1128’s conclusion was that Flag should yield arrays. by Austin Bales (at 417east) |
I don’t think your example is atypical at all; consider the following case with calling Receiver modifying methods seem to be a weakness with the current implementation of dirty tracking. ActiveRecord addresses this by requiring you to call Maybe there is a better pattern or ruby idiom to solve this? by Carl Porth |
I don’t love #attribute_will_change!, but what if you could set values to explicitly save.
by Austin Bales (at 417east) |
This is going to be resolved in 1.x.x series as it requires changes in dm-core and we won’t make it for 1.0.0 by Piotr Solnica (solnic) |
by Dan Kubb (dkubb) |
Note that pull request 33 (#33) + adding the DirtyMinder concept to Flag would conceptually fix this. |
@jpr5's pull request was merged which solves this problem. Closing this ticket. If the problem still persists please add a comment to this ticket, otherwise enjoy! |
Ok, my bad. That commit does not solve this issue yet. However the same lib can be used with this. @jpr5 has said he would look into it. |
Aaron Pfeiffer offered this temporary sollution in his post https://groups.google.com/d/msg/datamapper/JBkeBWxZUmI/H6nPD0kCWwcJ I had to update it just a little but it's working for me now. For example:
Maybe it will help someone else until they find a better way. I'm just getting my sea-legs with Ruby. This looks like a pretty challenging problem. |
DataMapper::Types::Flag caches values assigned/appended with the left shift
<<
operator, but fails to persist them on save().I've created a gist to illustrate the problem.
I might also add that finders like
Model.all(:flagprop => [:one, :two])
do not behave as (I) expected, but I really have no idea how they are supposed to work.See also:
#1128
Created by Austin Bales (at 417east) - 2009-12-21 05:26:02 UTC
Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1161
The text was updated successfully, but these errors were encountered: