Hi.
How to delete orphan tuples after a new object has been created through
has_one association?
Here''s an example:
# a user model
class User < ActiveRecord::Base
has_one :account
end
# an account model
class Account < ActiveRecord::Base
belongs_to :user
end
# a users table
id = 1
name = Pavel
id = 2
name = Elena
# an accounts table
id = 1
user_id = 1
type = ''silver''
id = 2
user_id = 2
type = ''gold''
Then, if I create a new account for the first user an orphan tuple will
stay in the accounts table:
>> User.find(1).create_account(:type => ''gold'')
# an accounts table
# an orphan tuple
id = 1
user_id = null
type = ''silver''
id = 2
user_id = 2
type = ''gold''
# a new tuple
id = 3
user_id = 1
type = ''gold''
So, how can I delete the tuple with id = 1 right after creating a new
account for the first user?
Thanks.
Ruby 1.9.2;
Rails 2.3.8.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.