Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Problem with Overriding Accessors
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
andrew8088  
View profile  
 More options Mar 29 2011, 7:15 am
From: andrew8088 <andrew8...@gmail.com>
Date: Tue, 29 Mar 2011 04:15:14 -0700 (PDT)
Local: Tues, Mar 29 2011 7:15 am
Subject: Problem with Overriding Accessors
I'm having an issue with overriding accessors; here's my model:

class User
  include DataMapper::Resource

  property :id, Serial
  property :username, String

  def username= new_username
    @usename = new_username.downcase
  end

end

The problem is that, when using a custom accessor like I have here,
the field doesn't get set; it gets set to null. I've found that I can
do this:

def username= new_username
    super new_username.downcase
end

And that works fine. Of course, not overriding the accessor works
too.

I copied the example from the documentation (http://rubydoc.info/
github/datamapper/dm-core/master/DataMapper/Property) and had the same
problem with it.

Has the syntax changed? Am I doing something wrong?

Thanks!

PS - if it matters, I'm using dm-core 1.1.0 in Ruby 1.9.2 on Snow
Leopard


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Stott  
View profile  
 More options Mar 29 2011, 8:01 am
From: Jonathan Stott <jonathan.st...@gmail.com>
Date: Tue, 29 Mar 2011 13:01:37 +0100
Local: Tues, Mar 29 2011 8:01 am
Subject: Re: [DataMapper] Problem with Overriding Accessors
Hi Andrew

The use of super is the correct usage.  That invokes the accessor, and
thus the appropriate dirtiness tracking mechanisms, which in turn
ensure the changed property is persisted to the datastore.  The
example in the docs is currently incorrect, though that syntax might
work at some point in the future (if/when improved dirtiness tracking
is added).  For now, use super.  Or "self[:property_name] =
'something'"

Regards
Jon

On 29 March 2011 12:15, andrew8088 <andrew8...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
andrew8088  
View profile  
 More options Mar 29 2011, 8:29 am
From: andrew8088 <andrew8...@gmail.com>
Date: Tue, 29 Mar 2011 05:29:43 -0700 (PDT)
Local: Tues, Mar 29 2011 8:29 am
Subject: Re: Problem with Overriding Accessors
Thanks!

On Mar 29, 8:01 am, Jonathan Stott <jonathan.st...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »