I think I''ve seen this mentioned before, but I can''t find it.
In the process of destroying a record, I want to assign nil to a
datetime field in another record that belongs to it.
However, when I say...
self.numbers.each do |n|
[...]
n.expires = nil
[...]
n.save
end
In my before_destroy method, n.expires doesn''t actually get set to nil,
either in unit testing or in "real life".
If I do the same thing in the console, it seems to work:
>> n = Number.find(35)
=> #<Number:0x24856b4
@attributes={"expires"=>"2007-01-27 16:15:14",
"id"=>"35"[...]}>>> n.expires = nil
=> nil>> n.save
=> true>> n = Number.find(35)
=> #<Number:0x2471358 @attributes={"expires"=>nil,
"id"=>"35"[...}>
Can somebody tell me what''s going on here?
--Al Evans
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi Al, Al Evans wrote:> I want to assign nil to a datetime field {...] > > However, when I say... > {...] > n.expires = nil > [...] > n.expires doesn''t actually get set to nil, > either in unit testing or in "real life". > > If I do the same thing in the console, it seems to work:What does your sql declaration for the field look like? Does it explicitly allow nil values? Just guessing here... Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> What does your sql declaration for the field look like? Does it > explicitly > allow nil values? Just guessing here...+---------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | [...] | expires | datetime | YES | | NULL | | [...] +---------------+--------------+------+-----+---------+----------------+ --Al Evans -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---