Comments (11)
<<
fails to invoke dirty tracking so calling save fails to see any changes.
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:
- Document this issue as an implementation detail for the user
- Override receiver modifying methods to invoke dirty tracking
- Freeze the attribute so it cannot be modified; the user has to reassign changes
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
from dm-types.
For example, you could do:
by Carl Porth
from dm-types.
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.
Is it that approach two is too complex or costly? I’m by no means a Ruby expert, but bear with me...
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)
from dm-types.
I don’t think your example is atypical at all; consider the following case with calling capitalize!
on a string attribute: http://gist.github.com/276969
Receiver modifying methods seem to be a weakness with the current implementation of dirty tracking. ActiveRecord addresses this by requiring you to call #{attribute}_will_change!
before modifying the receiver.
Maybe there is a better pattern or ruby idiom to solve this?
by Carl Porth
from dm-types.
I don’t love #attribute_will_change!, but what if you could set values to explicitly save.
p = Person.get(3)
p.first_name.capitalize!
p.visits << Visit.new()
p.save :first_name, :visits
by Austin Bales (at 417east)
from dm-types.
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)
from dm-types.
by Dan Kubb (dkubb)
from dm-types.
Note that pull request 33 (#33) + adding the DirtyMinder concept to Flag would conceptually fix this.
from dm-types.
@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!
from dm-types.
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.
from dm-types.
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:
account.status << :email_confirmed
account.taint! :status
account.save
STDERR.puts account.saved? ? 'account is saved' : 'account was not saved'
account.reload
p account.status # ==> [ :email_confirmed ]
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.
from dm-types.
Related Issues (20)
- DataMapper Incomatibilities with rails 3.1 HOT 1
- bcrypt-ruby update HOT 4
- IPAddress Property does not typecast Resolv::IPv4 / Resolv::IPv6 objects HOT 3
- Please update JSON dependency to 1.6.x HOT 7
- dm-types redefines the global CSV constant on Ruby 1.8 HOT 3
- ParanoidBoolean causes issues with belongs_to Relationships HOT 1
- DataMapper::Property::IPAddress attempts to typecase LIKE-queries HOT 5
- UUID: got error on jruby HOT 2
- uninitialized constant ClassName::Enum HOT 3
- Enums are nil when an already created object is fetched HOT 6
- multi-json dependency HOT 1
- Bump stringex dependency to ~>2.0.2 HOT 5
- [release 1.2] rspec failing HOT 1
- Upgrade to safe_yaml
- Exception when assigning an arbitrary string to a Json field
- brcypt-ruby name change HOT 6
- can't modify frozen NilClass HOT 12
- Missing code in release v1.2.2 HOT 3
- UUID missing from migration type map HOT 1
- Update json dependency HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dm-types.