Here is a problem: while the user is adding , deleting and modifying
data , data anomalies can arise, for example take the the two table A, B
which are joined by the intermediate join table A_B:
[A]
id:integer
name:string
[A_B]
a_id:integer
b_id:integer
[B]
id:integer
name:string
Now I have in A''s model file:
has_many :a_b, :dependent => :destroy
and in B''s model file :
has_many :a_b, :dependent => :destroy
Apparently sometimes the dependent destroy directive is not taking
place.
For example B is deleted from the database but the deleted record''s id
remains in A_B. This causes nil.nilclass exceptions ; what is the best
way of handling this? [more explanation see 1]
How to gracefully tackle these data anomalies that may arise?
{1}Elaboration :
example
[A]
[1:TestA]
[A_B]
[1,1]
[B]
[1:TestB]
--
Now despite the model file directive sometimes [B] is empty but [A_B]
remains and when I try to access A.A_B.name I get a nil class exception.
Currently when I encounter this errant intermediate record I delete and
move on but any other features if they exist would be great to learn
(sorry if my expectations are through the roof, but ROR is great)
--
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
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-24 01:21 UTC
Re: What is Best Way of Tackling Rising Data Anomalies
> > -- > Now despite the model file directive sometimes [B] is empty but [A_B] > remains and when I try to access A.A_B.name I get a nil class exception. > Currently when I encounter this errant intermediate record I delete and > move on but any other features if they exist would be great to learn > (sorry if my expectations are through the roof, but ROR is great)As far as I''m concerned, if you want a cast iron guarantee that your foo_id columns are just dangling then that guarentee has to be provided by the database (ie a foreign key constraint) Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---