Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Created January 23, 2013 22:32
Show Gist options
  • Save pmarreck/4614971 to your computer and use it in GitHub Desktop.
Save pmarreck/4614971 to your computer and use it in GitHub Desktop.
Why is the associated emails collection of the mailbox saved in 3.1, but not in 3.0? (The underlying code is exactly the same other than the Rails version.)
Rails 3.1:
>> Mailbox.first.emails.each(&:destroy); mb = Mailbox.first; eml = mb.emails.new(site: Site.first); mb.save
Mailbox Load (0.6ms) SELECT `mailboxes`.* FROM `mailboxes` WHERE `mailboxes`.`deleted_at` IS NULL LIMIT 1
Email Load (0.3ms) SELECT `emails`.* FROM `emails` WHERE `emails`.`mailbox_id` = 1
Mailbox Load (0.3ms) SELECT `mailboxes`.* FROM `mailboxes` WHERE `mailboxes`.`deleted_at` IS NULL LIMIT 1
Site Load (0.4ms) SELECT `sites`.* FROM `sites` WHERE `sites`.`deleted_at` IS NULL LIMIT 1
(0.2ms) BEGIN
(0.4ms) SELECT 1 FROM `mailboxes` WHERE (LOWER(`mailboxes`.`email`) = LOWER('[email protected]') AND `mailboxes`.`id` != 1 AND `mailboxes`.`site_id` = 3 AND `mailboxes`.`deleted_at` IS NULL) LIMIT 1
(0.3ms) UPDATE `mailboxes` SET `updated_at` = '2013-01-23 22:22:55', `comm_options` = '--- \n', `lock_version` = 5 WHERE (`mailboxes`.`id` = 1 AND `mailboxes`.`lock_version` = 4)
SQL (0.4ms) INSERT INTO `emails` (`bcc`, `body`, `cc`, `created_at`, `delivered_to`, `email_client_id`, `email_out_status_id`, `email_template_id`, `error_count`, `forward_from`, `forward_reply_to`, `from`, `header`, `hidden_at`, `hidden_by_id`, `in_reply_to`, `interaction_direction_id`, `last_error`, `mailbox_id`, `message_id`, `orig_email_id`, `orig_ticket_id`, `outbound_mailbox_id`, `reply_to`, `send_at`, `sender`, `sender_group_id`, `sender_user_id`, `sent_at`, `site_id`, `size`, `subject`, `ticket_attachments_count`, `ticket_id`, `to`, `uid`, `updated_at`, `x_mailer`) VALUES (NULL, NULL, NULL, '2013-01-23 22:22:55', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, NULL, 1, NULL, NULL, NULL, NULL, NULL, '2013-01-23 22:22:55', NULL, NULL, NULL, NULL, 2, NULL, '', 0, NULL, NULL, NULL, '2013-01-23 22:22:55', NULL)
(0.4ms) COMMIT
Rails 3.0:
>> Mailbox.first.emails.each(&:destroy); mb = Mailbox.first; eml = mb.emails.new(site: Site.first); mb.save
[DEBUG: 01/23 17:25:07 #32136] Mailbox Load (0.4ms) SELECT `mailboxes`.* FROM `mailboxes` WHERE `mailboxes`.`deleted_at` IS NULL LIMIT 1
[DEBUG: 01/23 17:25:07 #32136] Site Load (0.3ms) SELECT `sites`.* FROM `sites` WHERE `sites`.`deleted_at` IS NULL LIMIT 1
[DEBUG: 01/23 17:25:07 #32136] SQL (0.4ms) BEGIN
[DEBUG: 01/23 17:25:07 #32136] SQL (0.4ms) SELECT 1 FROM `mailboxes` WHERE `mailboxes`.`site_id` = 3 AND `mailboxes`.`deleted_at` IS NULL AND (LOWER(`mailboxes`.`email`) = LOWER('[email protected]')) AND (`mailboxes`.id <> 1) LIMIT 1
[DEBUG: 01/23 17:25:07 #32136] AREL (0.4ms) UPDATE `mailboxes` SET `comm_options` = NULL, `lock_version` = 6 WHERE (`mailboxes`.`id` = 1 AND `mailboxes`.`lock_version` = 5)
[DEBUG: 01/23 17:25:07 #32136] SQL (0.5ms) COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment