[Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-04 Thread Paul
Rails is great and most things just work easily. However, I've never been able to get a definite answer on whether one should do, validates :parent, :presence => true or, validates :parent_id, :presence => true given, class Parent end class Child belongs_to :parent end I've always thought

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-04 Thread Michael Pavling
On 4 February 2011 20:30, Paul wrote: > I've always thought that validating the :parent (and not the foreign > key) is the *more* correct thing to do ... but I don't understand why > Rails does not reset the parent association when the parent_id is > changed as demonstrated here, > > Any thoughts?

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-04 Thread Michael Pavling
On 4 February 2011 20:36, Michael Pavling wrote: > That's my preference anyhoo... oops! This is rails-core list... take it over to "talk" apologies... -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email t

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-04 Thread Ernie Miller
On Feb 4, 2011, at 3:30 PM, Paul wrote: > Rails is great and most things just work easily. However, I've never > been able to get a definite answer on whether one should do, > > validates :parent, :presence => true > > or, > > validates :parent_id, :presence => true > > given, > > class Paren

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-04 Thread Jon Leighton
Hey, In edge rails there is a mechanism for checking whether the loaded association target is "stale" - so if you do record.foo_id = x, then record.foo will load the target afresh. I'm not sure whether it necessarily works with validation like this, but hopefully it does. [I haven't tried.] Just

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-05 Thread Michael Koziarski
On 5/02/2011, at 9:30 AM, Paul wrote: > Rails is great and most things just work easily. However, I've never > been able to get a definite answer on whether one should do, > > validates :parent, :presence => true > > or, > > validates :parent_id, :presence => true > Validate the object, not the

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-06 Thread Rainer Frey
On Fri, Feb 4, 2011 at 9:36 PM, Michael Pavling wrote: > On 4 February 2011 20:30, Paul wrote: >> I've always thought that validating the :parent (and not the foreign >> key) is the *more* correct thing to do >> I've never >> been able to get a definite answer on whether one should do, >> >> vali

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-07 Thread Xavier Noria
On Sun, Feb 6, 2011 at 2:10 PM, Rainer Frey wrote: > Unfortunately the Rails Guide on Active Record Validation and > Callbacks says (Section 3.9): > "If you want to be sure that an association is present, you’ll need to > test whether the foreign key used to map the association is present, > and

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-07 Thread Rainer Frey
On Mon, Feb 7, 2011 at 11:58 AM, Xavier Noria wrote: > On Sun, Feb 6, 2011 at 2:10 PM, Rainer Frey wrote: > >> Unfortunately the Rails Guide on Active Record Validation and >> Callbacks says (Section 3.9): >> "If you want to be sure that an association is present, you’ll need to >> test whether t

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-07 Thread Jon Leighton
On Mon, 2011-02-07 at 14:28 +0100, Rainer Frey wrote: > On Mon, Feb 7, 2011 at 11:58 AM, Xavier Noria wrote: > > On Sun, Feb 6, 2011 at 2:10 PM, Rainer Frey wrote: > > > >> Unfortunately the Rails Guide on Active Record Validation and > >> Callbacks says (Section 3.9): > >> "If you want to be sur

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-07 Thread Xavier Noria
On Mon, Feb 7, 2011 at 2:28 PM, Rainer Frey wrote: > But this thread seems to suggest one should simply validate the > association attribute instead. Is that not sufficient then? You can't still be sure the association is valid, because the associated object is cached if previously fetched, and

Re: [Rails-core] Why does Rails not reset the association when the id is changed?

2011-02-07 Thread Jon Leighton
Hey, On Mon, 2011-02-07 at 15:22 +0100, Xavier Noria wrote: > On Mon, Feb 7, 2011 at 2:28 PM, Rainer Frey wrote: > > > But this thread seems to suggest one should simply validate the > > association attribute instead. Is that not sufficient then? > > You can't still be sure the association is v