Skip to content

Instantly share code, notes, and snippets.

@sekmo
Last active April 6, 2025 15:24
Show Gist options
  • Save sekmo/92d0e2278730140f97ffd23655137331 to your computer and use it in GitHub Desktop.
Save sekmo/92d0e2278730140f97ffd23655137331 to your computer and use it in GitHub Desktop.
Rails includes behavior
# Return.find(1078).update(request_approved_by: User.find(787), request_cancelled_by: User.find(783))
# branding_id = 242
# return_id = 1078
# return_request_condition_id_1 = 105
# return_request_condition_id_2 = 106
# ReturnRequestConditionCheck.create!(return_id: 1078, return_request_condition_id: 105, condition_met: false, actual_values: ["3"])
# ReturnRequestConditionCheck.create!(return_id: 1078, return_request_condition_id: 106, condition_met: true, actual_values: ["800"])
ActiveRecord::Base.logger = Logger.new(STDOUT)
class Return < ApplicationRecord
belongs_to :request_approved_by, optional: true, class_name: "User"
belongs_to :request_cancelled_by, optional: true, class_name: "User"
end
merchant = Merchant.find 130
return_id = 1078
return_record = merchant.returns.includes(
request_approved_by: {},
request_cancelled_by: {},
order: {shipment_items: [:sku]},
return_label: [:return_events],
return_line_items: [:photos, :sku],
return_request_condition_checks: [:return_request_condition]
).find(return_id)
puts "------------------------------- TRIGGERING QUERY -------------------------------"
{
approved_by_user_name: return_record.request_approved_by&.name,
cancelled_by_user_name: return_record.request_cancelled_by&.name,
return_request_condition_checks: return_record.return_request_condition_checks.map do |rrcc|
{
condition_met: rrcc.condition_met,
actual_values: rrcc.actual_values,
return_request_condition: {
target_field: rrcc.return_request_condition.target_field,
operator: rrcc.return_request_condition.operator,
values: rrcc.return_request_condition.values,
deleted_at: rrcc.return_request_condition.deleted_at&.utc&.iso8601(3)
}
}
end
}
D, [2025-04-06T15:17:50.306317 #28876] DEBUG -- : ActiveRecord::SchemaMigration Load (7.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
D, [2025-04-06T15:17:50.325729 #28876] DEBUG -- : Merchant Load (3.4ms) SELECT "merchants"."id", "merchants"."name", "merchants"."contact_email", "merchants"."phone", "merchants"."country", "merchants"."city", "merchants"."state", "merchants"."postal_code", "merchants"."street1", "merchants"."street2", "merchants"."logo", "merchants"."return_policy", "merchants"."packaging_preference", "merchants"."payment_details", "merchants"."test_account", "merchants"."created_at", "merchants"."updated_at", "merchants"."postal_name", "merchants"."billing_address_postal_name", "merchants"."billing_address_country", "merchants"."billing_address_city", "merchants"."billing_address_state", "merchants"."billing_address_postal_code", "merchants"."billing_address_street1", "merchants"."billing_address_street2", "merchants"."deleted_at", "merchants"."image_data", "merchants"."contract_signing_date", "merchants"."active", "merchants"."billing_notes", "merchants"."payments_goal_in_days", "merchants"."shipping_contract_id", "merchants"."agreed_cut_off_time", "merchants"."throughput", "merchants"."multishop_enabled", "merchants"."merchant_shipments_enabled", "merchants"."sku_confirmation_rule", "merchants"."street", "merchants"."house_number", "merchants"."shipping_contracts_methods_merchant_id", "merchants"."finance_currency_id", "merchants"."packaging_guidelines_url", "merchants"."block_inventory_for_older_orders", "merchants"."registration_court_and_number", "merchants"."managing_directors", "merchants"."uuid", "merchants"."percentage_weight_buffer", "merchants"."shipments_need_manual_weight", "merchants"."qa_check_interval", "merchants"."inventory_minimum", "merchants"."require_manual_sku_weight_confirmation", "merchants"."bulk_picking_limit", "merchants"."max_automatic_shipment_weight_threshold_in_kg", "merchants"."fulfillment_setup", "merchants"."max_filler_material_weight_kg", "merchants"."eori_number", "merchants"."lucid_number", "merchants"."preferred_currency", "merchants"."main_vat_number", "merchants"."billing_emails", "merchants"."preferred_payment_method", "merchants"."vat_numbers", "merchants"."joined_delivery_predictions_waitlist", "merchants"."in_onboarding", "merchants"."serial_number_tracking_enabled", "merchants"."cart_picking_enabled", "merchants"."batch_tracking_enabled", "merchants"."delivery_and_allocations_flow_enabled", "merchants"."delivery_and_allocations_flow_available", "merchants"."uk_eori_number", "merchants"."hide_onboarding", "merchants"."sepa_document_data", "merchants"."bdo_number", "merchants"."lucid_pdf_data", "merchants"."using_two_sendcloud_accounts", "merchants"."invoicing_period", "merchants"."automatic_sku_confirmation_method_change_disabled", "merchants"."box_specific_rules_activated_at", "merchants"."packaging_settings_activated_at", "merchants"."show_packaging_guidelines_url_in_hive_app", "merchants"."tier_id", "merchants"."batch_management_enabled", "merchants"."iban", "merchants"."bic", "merchants"."edd_feature_flag_enabled", "merchants"."skip_invoicing_for_custom_outer_packaging", "merchants"."skip_invoicing_for_custom_filling_material", "merchants"."ioss_number", "merchants"."weight_check_z_index_score", "merchants"."allowed_service_bundles", "merchants"."contractual_start_date", "merchants"."returns_approval_feature_flag" FROM "merchants" WHERE "merchants"."id" = 130 LIMIT 1
D, [2025-04-06T15:17:50.419319 #28876] DEBUG -- : Return Load (3.3ms) SELECT "returns"."id", "returns"."order_id", "returns"."status", "returns"."return_reason", "returns"."product_condition", "returns"."merchant_guidance", "returns"."items_returned", "returns"."received_at", "returns"."created_at", "returns"."updated_at", "returns"."image_data", "returns"."created_by_id", "returns"."notes", "returns"."return_box_id", "returns"."merchant_notes", "returns"."weight_in_kg", "returns"."tracking_code", "returns"."shipping_contracts_method_id", "returns"."customer_return_reason", "returns"."warehouse_id", "returns"."settlement_option", "returns"."mx_notified", "returns"."deleted_at", "returns"."created_via", "returns"."started_processing_at", "returns"."started_processing_by_id", "returns"."completed_handling_at", "returns"."completed_handling_by_id", "returns"."return_reason_type", "returns"."reviewed", "returns"."return_delivery_method_id", "returns"."external_refund_id", "returns"."manually_marked_as_refunded", "returns"."refund_completed_by_id", "returns"."refund_completed_at", "returns"."refunded_amount_in_cents", "returns"."external_gift_card_id", "returns"."refunded_currency", "returns"."shop_id", "returns"."all_returns_were_requiring_request", "returns"."request_approved_by_id", "returns"."request_approved_at", "returns"."request_cancelled_by_id", "returns"."request_cancelled_at", "returns"."request_cancelled_description" FROM "returns" INNER JOIN "shops" ON "returns"."shop_id" = "shops"."id" WHERE "returns"."deleted_at" IS NULL AND "shops"."deleted_at" IS NULL AND "shops"."merchant_id" = 130 AND "returns"."id" = 1078 LIMIT 1
D, [2025-04-06T15:17:50.459059 #28876] DEBUG -- : User Load (2.2ms) SELECT "users"."id", "users"."created_at", "users"."updated_at", "users"."email", "users"."encrypted_password", "users"."reset_password_token", "users"."reset_password_sent_at", "users"."remember_created_at", "users"."sign_in_count", "users"."current_sign_in_at", "users"."last_sign_in_at", "users"."current_sign_in_ip", "users"."last_sign_in_ip", "users"."provider", "users"."uid", "users"."confirmation_token", "users"."confirmed_at", "users"."confirmation_sent_at", "users"."phone", "users"."full_name", "users"."unconfirmed_email", "users"."token", "users"."admin_role", "users"."warehouse_manager_role", "users"."warehouse_worker_role", "users"."merchant_role", "users"."deleted_at", "users"."image_data", "users"."auth_token", "users"."shyftplan_punch_token", "users"."shyftplan_staff_number", "users"."token_expiry", "users"."super_admin_role", "users"."logistics_provider_id", "users"."deactivated_at", "users"."role_permission_id", "users"."mx_role_id" FROM "users" WHERE "users"."id" IN (787, 783)
D, [2025-04-06T15:17:50.481078 #28876] DEBUG -- : Order Load (2.9ms) SELECT "orders"."id", "orders"."shop_id", "orders"."customer_id", "orders"."platform_order_id", "orders"."postal_name", "orders"."service_fee", "orders"."estimated_delivery_date", "orders"."created_at", "orders"."updated_at", "orders"."name", "orders"."internal_status", "orders"."deleted_at", "orders"."payment_method", "orders"."financial_status", "orders"."customer_language", "orders"."total_amount", "orders"."customer_note", "orders"."merchant_note", "orders"."currency", "orders"."postal_first_name", "orders"."postal_last_name", "orders"."merchant_name", "orders"."state_code", "orders"."fulfillment_status", "orders"."tags", "orders"."origin_admin_url", "orders"."imported_at", "orders"."shop_updated_at", "orders"."disable_address_sync", "orders"."status_changed_at", "orders"."internal_issues", "orders"."external_issues", "orders"."mondial_relay_id", "orders"."mondial_relay_zip", "orders"."order_type", "orders"."returns_count", "orders"."manual_order", "orders"."recipient_instructions", "orders"."customer_facing_order_name", "orders"."prioritized", "orders"."merchant_custom_barcode", "orders"."merchant_custom_text", "orders"."merchant_custom_qrcode", "orders"."total_outstanding_in_cents", "orders"."shipping_cost_in_cents", "orders"."uuid", "orders"."external_id", "orders"."external_order_name", "orders"."latest_ship_date", "orders"."latest_delivery_date", "orders"."merchant_custom_packaging", "orders"."merchant_note_updated_at", "orders"."metadata", "orders"."initial_status_reason", "orders"."presentment_currency", "orders"."external_refund_ids", "orders"."presentment_shipping_cost_in_cents", "orders"."external_payment_processed_at", "orders"."warehouse_allocated", "orders"."marketplace_id", "orders"."marketplace_identification_rule_id", "orders"."total_tax_in_cents", "orders"."custom_metadata", "orders"."marketplace_order_name", "orders"."created_by_user_id", "orders"."buyer_vat_number" FROM "orders" WHERE "orders"."deleted_at" IS NULL AND "orders"."id" = 1164361
D, [2025-04-06T15:17:50.516101 #28876] DEBUG -- : Dx::ReturnLabel Load (1.8ms) SELECT "dx_return_labels"."id", "dx_return_labels"."external_id", "dx_return_labels"."response_payload", "dx_return_labels"."request_payload", "dx_return_labels"."label_provider", "dx_return_labels"."return_delivery_method_id", "dx_return_labels"."return_id", "dx_return_labels"."created_at", "dx_return_labels"."updated_at", "dx_return_labels"."external_account_id", "dx_return_labels"."uuid", "dx_return_labels"."related_shipment_id", "dx_return_labels"."tracking_code" FROM "dx_return_labels" WHERE "dx_return_labels"."return_id" = 1078
D, [2025-04-06T15:17:50.527457 #28876] DEBUG -- : Ox::ReturnLineItem Load (1.5ms) SELECT "return_line_items"."id", "return_line_items"."return_id", "return_line_items"."sku_id", "return_line_items"."inventory_batch_id", "return_line_items"."return_item_id", "return_line_items"."condition", "return_line_items"."follow_up_action", "return_line_items"."created_at", "return_line_items"."updated_at", "return_line_items"."basket_allocation_id" FROM "return_line_items" WHERE "return_line_items"."return_id" = 1078
D, [2025-04-06T15:17:50.530736 #28876] DEBUG -- : ReturnRequestConditionCheck Load (1.4ms) SELECT "return_request_condition_checks"."id", "return_request_condition_checks"."return_id", "return_request_condition_checks"."return_request_condition_id", "return_request_condition_checks"."condition_met", "return_request_condition_checks"."actual_values", "return_request_condition_checks"."created_at", "return_request_condition_checks"."updated_at" FROM "return_request_condition_checks" WHERE "return_request_condition_checks"."return_id" = 1078
D, [2025-04-06T15:17:50.549184 #28876] DEBUG -- : Shipment Load (3.2ms) SELECT "shipments"."id", "shipments"."order_id", "shipments"."tracking_code", "shipments"."status", "shipments"."created_at", "shipments"."updated_at", "shipments"."weight", "shipments"."deleted_at", "shipments"."shipped_at", "shipments"."option_title", "shipments"."shipping_contracts_methods_merchant_id", "shipments"."shipping_contracts_method_id", "shipments"."cutoff_at", "shipments"."ready_for_fulfillment_at", "shipments"."rules_overwritten", "shipments"."status_changed_at", "shipments"."internal_issues", "shipments"."external_issues", "shipments"."split_from_shipment_id", "shipments"."warehouse_id", "shipments"."split_reason", "shipments"."split_by_user_id", "shipments"."split_note", "shipments"."bulk_picking", "shipments"."packing_slip_data", "shipments"."expected_fulfillment_at", "shipments"."expected_shipping_contracts_method_id", "shipments"."expected_weight", "shipments"."expected_packaging_sku_id", "shipments"."started_picking_at", "shipments"."finished_picking_at", "shipments"."started_packing_at", "shipments"."finished_packing_at", "shipments"."expected_cutoff_at", "shipments"."effective_weight", "shipments"."ox_daily_carrier_pickup_id", "shipments"."delivered_at", "shipments"."days_shipped_to_delivered", "shipments"."send_in_basket", "shipments"."not_enough_stock", "shipments"."pallete_delivery_cost", "shipments"."delivery_status", "shipments"."calculated_weight_in_kg", "shipments"."needs_manual_weight", "shipments"."merchant_id", "shipments"."shipped_with_jid", "shipments"."needs_manual_weight_for_qa", "shipments"."weight_error_term", "shipments"."external_fulfillment_id", "shipments"."manual_weight_reason", "shipments"."logistics_provider_id", "shipments"."packaging_longest", "shipments"."packaging_medium", "shipments"."packaging_shortest", "shipments"."uuid", "shipments"."pickable_skus_count", "shipments"."requires_customs_cache", "shipments"."default_packaging_use_id", "shipments"."marketplace_id", "shipments"."prioritized", "shipments"."order_created_at", "shipments"."pickable_items_count", "shipments"."requested_shipping_contracts_method_id", "shipments"."bulk_packing_parent_shipment_id", "shipments"."bulk_packing_v2_started", "shipments"."expected_contract_method_unreliable_reason", "shipments"."bulk_packing_width_in_mm", "shipments"."bulk_packing_height_in_mm", "shipments"."bulk_packing_length_in_mm" FROM "shipments" WHERE "shipments"."deleted_at" IS NULL AND "shipments"."order_id" = 1164361
D, [2025-04-06T15:17:50.580650 #28876] DEBUG -- : Dx::ReturnEvent Load (1.6ms) SELECT "dx_return_events"."id", "dx_return_events"."external_created_at", "dx_return_events"."external_received_at", "dx_return_events"."original_status", "dx_return_events"."status", "dx_return_events"."received_from", "dx_return_events"."dx_return_label_id", "dx_return_events"."created_at", "dx_return_events"."updated_at" FROM "dx_return_events" WHERE "dx_return_events"."dx_return_label_id" = 234
D, [2025-04-06T15:17:50.603265 #28876] DEBUG -- : ReturnRequestCondition Load (1.4ms) SELECT "return_request_conditions"."id", "return_request_conditions"."operator", "return_request_conditions"."target_field", "return_request_conditions"."values", "return_request_conditions"."branding_id", "return_request_conditions"."deleted_at", "return_request_conditions"."created_at", "return_request_conditions"."updated_at" FROM "return_request_conditions" WHERE "return_request_conditions"."id" IN (105, 106)
D, [2025-04-06T15:17:50.614961 #28876] DEBUG -- : ShipmentItem Load (2.0ms) SELECT "shipment_items"."id", "shipment_items"."shipment_id", "shipment_items"."created_at", "shipment_items"."updated_at", "shipment_items"."deleted_at", "shipment_items"."quantity", "shipment_items"."confirmed", "shipment_items"."sku_id", "shipment_items"."internal_issues", "shipment_items"."external_issues", "shipment_items"."total_sku_quantity", "shipment_items"."customise", "shipment_items"."external_id", "shipment_items"."needs_reshuffling_issue", "shipment_items"."new_sku_issue", "shipment_items"."out_of_stock_issue", "shipment_items"."not_enough_stock", "shipment_items"."parent_sku_id", "shipment_items"."packaging_rule_sku_id", "shipment_items"."skip_fulfillment", "shipment_items"."insertion_strategy", "shipment_items"."skip_fulfillment_reason", "shipment_items"."price_per_unit_in_cents", "shipment_items"."price_per_unit_in_cents_with_discount", "shipment_items"."cost_per_unit_in_cents", "shipment_items"."inventory_batch_ids", "shipment_items"."presentment_price_per_unit_in_cents_with_discount", "shipment_items"."stock_issues_caused_by_batch_selection", "shipment_items"."not_enough_pickable_stock", "shipment_items"."presentment_price_per_unit_in_cents" FROM "shipment_items" WHERE "shipment_items"."deleted_at" IS NULL AND "shipment_items"."shipment_id" = 652037
D, [2025-04-06T15:17:50.633876 #28876] DEBUG -- : Sku Load (2.5ms) SELECT "skus"."id", "skus"."merchant_sku", "skus"."name", "skus"."shop_depth", "skus"."shop_photo", "skus"."status", "skus"."tag1", "skus"."tag2", "skus"."tag3", "skus"."fulfilled_by", "skus"."created_at", "skus"."updated_at", "skus"."image_data", "skus"."box_image_data", "skus"."lead_time_in_days", "skus"."extension_definition_type", "skus"."extension_definition_id", "skus"."sku_type", "skus"."cost", "skus"."country_code_of_origin", "skus"."hs_code", "skus"."barcode", "skus"."merchant_id", "skus"."verified", "skus"."sync_source_shop_sku_id", "skus"."internal_barcode", "skus"."available_to_all_merchants", "skus"."identification_requirement", "skus"."alternative_barcode", "skus"."vendor", "skus"."weight_in_kg", "skus"."longest", "skus"."medium", "skus"."shortest", "skus"."procured_by_hive", "skus"."customisable", "skus"."send_individually", "skus"."batch_tracking_enabled", "skus"."shop_weight_in_kg", "skus"."bio_certified", "skus"."shop_hs_code", "skus"."shop_cost", "skus"."shop_country_code_of_origin", "skus"."measured_weights_count", "skus"."weight_standard_deviation_in_kg", "skus"."weight_standard_error_in_kg", "skus"."mean_weight_in_kg", "skus"."inventory_minimum", "skus"."vat_rate", "skus"."uid", "skus"."box_category", "skus"."inner_longest", "skus"."inner_medium", "skus"."inner_shortest", "skus"."serial_number_tracking_enabled", "skus"."track_serial_numbers_in", "skus"."imported_shop_photo_data", "skus"."return_policy_in_days", "skus"."strict_serial_number_tracking", "skus"."b2c_shelf_life_in_weeks", "skus"."b2b_shelf_life_in_weeks", "skus"."ito_shelf_life_in_weeks", "skus"."kit_shelf_life_in_weeks", "skus"."dangerous", "skus"."un_number", "skus"."fc_notes", "skus"."send_in_own_packaging", "skus"."dummy_filling_material", "skus"."base_sku_id", "skus"."items_per_case", "skus"."created_by_id" FROM "skus" WHERE "skus"."id" = 123123
------------------------------- TRIGGERING QUERY -------------------------------
=>
{approved_by_user_name: "Francesco Mari",
cancelled_by_user_name: "internaluser dojo staging",
return_request_condition_checks:
[{condition_met: false,
actual_values: ["3"],
return_request_condition: {target_field: "customer_orders_count", operator: "greater_than", values: ["4"], deleted_at: nil}},
{condition_met: true,
actual_values: ["800"],
return_request_condition: {target_field: "total_ordered_items_price", operator: "greater_than", values: ["600"], deleted_at: nil}}]}
# users table queried only 1 time
# Return.find(1078).update(request_approved_by: User.find(787), request_cancelled_by: User.find(783))
# branding_id = 242
# return_id = 1078
# return_request_condition_id_1 = 105
# return_request_condition_id_2 = 106
# ReturnRequestConditionCheck.create!(return_id: 1078, return_request_condition_id: 105, condition_met: false, actual_values: ["3"])
# ReturnRequestConditionCheck.create!(return_id: 1078, return_request_condition_id: 106, condition_met: true, actual_values: ["800"])
ActiveRecord::Base.logger = Logger.new(STDOUT)
class Return < ApplicationRecord
belongs_to :request_approved_by, optional: true, class_name: "User"
belongs_to :request_cancelled_by, optional: true, class_name: "User"
end
merchant = Merchant.find 130
return_id = 1078
return_record = merchant.returns.includes(
:request_approved_by,
:request_cancelled_by,
order: {shipment_items: [:sku]},
return_label: [:return_events],
return_line_items: [:photos, :sku],
return_request_condition_checks: [:return_request_condition]
).find(return_id)
puts "------------------------------- TRIGGERING QUERY -------------------------------"
{
approved_by_user_name: return_record.request_approved_by&.name,
cancelled_by_user_name: return_record.request_cancelled_by&.name,
return_request_condition_checks: return_record.return_request_condition_checks.map do |rrcc|
{
condition_met: rrcc.condition_met,
actual_values: rrcc.actual_values,
return_request_condition: {
target_field: rrcc.return_request_condition.target_field,
operator: rrcc.return_request_condition.operator,
values: rrcc.return_request_condition.values,
deleted_at: rrcc.return_request_condition.deleted_at&.utc&.iso8601(3)
}
}
end
}
D, [2025-04-06T15:14:19.026864 #28843] DEBUG -- : ActiveRecord::SchemaMigration Load (6.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
D, [2025-04-06T15:14:19.046493 #28843] DEBUG -- : Merchant Load (3.4ms) SELECT "merchants"."id", "merchants"."name", "merchants"."contact_email", "merchants"."phone", "merchants"."country", "merchants"."city", "merchants"."state", "merchants"."postal_code", "merchants"."street1", "merchants"."street2", "merchants"."logo", "merchants"."return_policy", "merchants"."packaging_preference", "merchants"."payment_details", "merchants"."test_account", "merchants"."created_at", "merchants"."updated_at", "merchants"."postal_name", "merchants"."billing_address_postal_name", "merchants"."billing_address_country", "merchants"."billing_address_city", "merchants"."billing_address_state", "merchants"."billing_address_postal_code", "merchants"."billing_address_street1", "merchants"."billing_address_street2", "merchants"."deleted_at", "merchants"."image_data", "merchants"."contract_signing_date", "merchants"."active", "merchants"."billing_notes", "merchants"."payments_goal_in_days", "merchants"."shipping_contract_id", "merchants"."agreed_cut_off_time", "merchants"."throughput", "merchants"."multishop_enabled", "merchants"."merchant_shipments_enabled", "merchants"."sku_confirmation_rule", "merchants"."street", "merchants"."house_number", "merchants"."shipping_contracts_methods_merchant_id", "merchants"."finance_currency_id", "merchants"."packaging_guidelines_url", "merchants"."block_inventory_for_older_orders", "merchants"."registration_court_and_number", "merchants"."managing_directors", "merchants"."uuid", "merchants"."percentage_weight_buffer", "merchants"."shipments_need_manual_weight", "merchants"."qa_check_interval", "merchants"."inventory_minimum", "merchants"."require_manual_sku_weight_confirmation", "merchants"."bulk_picking_limit", "merchants"."max_automatic_shipment_weight_threshold_in_kg", "merchants"."fulfillment_setup", "merchants"."max_filler_material_weight_kg", "merchants"."eori_number", "merchants"."lucid_number", "merchants"."preferred_currency", "merchants"."main_vat_number", "merchants"."billing_emails", "merchants"."preferred_payment_method", "merchants"."vat_numbers", "merchants"."joined_delivery_predictions_waitlist", "merchants"."in_onboarding", "merchants"."serial_number_tracking_enabled", "merchants"."cart_picking_enabled", "merchants"."batch_tracking_enabled", "merchants"."delivery_and_allocations_flow_enabled", "merchants"."delivery_and_allocations_flow_available", "merchants"."uk_eori_number", "merchants"."hide_onboarding", "merchants"."sepa_document_data", "merchants"."bdo_number", "merchants"."lucid_pdf_data", "merchants"."using_two_sendcloud_accounts", "merchants"."invoicing_period", "merchants"."automatic_sku_confirmation_method_change_disabled", "merchants"."box_specific_rules_activated_at", "merchants"."packaging_settings_activated_at", "merchants"."show_packaging_guidelines_url_in_hive_app", "merchants"."tier_id", "merchants"."batch_management_enabled", "merchants"."iban", "merchants"."bic", "merchants"."edd_feature_flag_enabled", "merchants"."skip_invoicing_for_custom_outer_packaging", "merchants"."skip_invoicing_for_custom_filling_material", "merchants"."ioss_number", "merchants"."weight_check_z_index_score", "merchants"."allowed_service_bundles", "merchants"."contractual_start_date", "merchants"."returns_approval_feature_flag" FROM "merchants" WHERE "merchants"."id" = 130 LIMIT 1
D, [2025-04-06T15:14:19.144959 #28843] DEBUG -- : Return Load (3.2ms) SELECT "returns"."id", "returns"."order_id", "returns"."status", "returns"."return_reason", "returns"."product_condition", "returns"."merchant_guidance", "returns"."items_returned", "returns"."received_at", "returns"."created_at", "returns"."updated_at", "returns"."image_data", "returns"."created_by_id", "returns"."notes", "returns"."return_box_id", "returns"."merchant_notes", "returns"."weight_in_kg", "returns"."tracking_code", "returns"."shipping_contracts_method_id", "returns"."customer_return_reason", "returns"."warehouse_id", "returns"."settlement_option", "returns"."mx_notified", "returns"."deleted_at", "returns"."created_via", "returns"."started_processing_at", "returns"."started_processing_by_id", "returns"."completed_handling_at", "returns"."completed_handling_by_id", "returns"."return_reason_type", "returns"."reviewed", "returns"."return_delivery_method_id", "returns"."external_refund_id", "returns"."manually_marked_as_refunded", "returns"."refund_completed_by_id", "returns"."refund_completed_at", "returns"."refunded_amount_in_cents", "returns"."external_gift_card_id", "returns"."refunded_currency", "returns"."shop_id", "returns"."all_returns_were_requiring_request", "returns"."request_approved_by_id", "returns"."request_approved_at", "returns"."request_cancelled_by_id", "returns"."request_cancelled_at", "returns"."request_cancelled_description" FROM "returns" INNER JOIN "shops" ON "returns"."shop_id" = "shops"."id" WHERE "returns"."deleted_at" IS NULL AND "shops"."deleted_at" IS NULL AND "shops"."merchant_id" = 130 AND "returns"."id" = 1078 LIMIT 1
D, [2025-04-06T15:14:19.175743 #28843] DEBUG -- : User Load (2.1ms) SELECT "users"."id", "users"."created_at", "users"."updated_at", "users"."email", "users"."encrypted_password", "users"."reset_password_token", "users"."reset_password_sent_at", "users"."remember_created_at", "users"."sign_in_count", "users"."current_sign_in_at", "users"."last_sign_in_at", "users"."current_sign_in_ip", "users"."last_sign_in_ip", "users"."provider", "users"."uid", "users"."confirmation_token", "users"."confirmed_at", "users"."confirmation_sent_at", "users"."phone", "users"."full_name", "users"."unconfirmed_email", "users"."token", "users"."admin_role", "users"."warehouse_manager_role", "users"."warehouse_worker_role", "users"."merchant_role", "users"."deleted_at", "users"."image_data", "users"."auth_token", "users"."shyftplan_punch_token", "users"."shyftplan_staff_number", "users"."token_expiry", "users"."super_admin_role", "users"."logistics_provider_id", "users"."deactivated_at", "users"."role_permission_id", "users"."mx_role_id" FROM "users" WHERE "users"."id" = 787
D, [2025-04-06T15:14:19.196211 #28843] DEBUG -- : User Load (1.4ms) SELECT "users"."id", "users"."created_at", "users"."updated_at", "users"."email", "users"."encrypted_password", "users"."reset_password_token", "users"."reset_password_sent_at", "users"."remember_created_at", "users"."sign_in_count", "users"."current_sign_in_at", "users"."last_sign_in_at", "users"."current_sign_in_ip", "users"."last_sign_in_ip", "users"."provider", "users"."uid", "users"."confirmation_token", "users"."confirmed_at", "users"."confirmation_sent_at", "users"."phone", "users"."full_name", "users"."unconfirmed_email", "users"."token", "users"."admin_role", "users"."warehouse_manager_role", "users"."warehouse_worker_role", "users"."merchant_role", "users"."deleted_at", "users"."image_data", "users"."auth_token", "users"."shyftplan_punch_token", "users"."shyftplan_staff_number", "users"."token_expiry", "users"."super_admin_role", "users"."logistics_provider_id", "users"."deactivated_at", "users"."role_permission_id", "users"."mx_role_id" FROM "users" WHERE "users"."id" = 783
D, [2025-04-06T15:14:19.209553 #28843] DEBUG -- : Order Load (2.9ms) SELECT "orders"."id", "orders"."shop_id", "orders"."customer_id", "orders"."platform_order_id", "orders"."postal_name", "orders"."service_fee", "orders"."estimated_delivery_date", "orders"."created_at", "orders"."updated_at", "orders"."name", "orders"."internal_status", "orders"."deleted_at", "orders"."payment_method", "orders"."financial_status", "orders"."customer_language", "orders"."total_amount", "orders"."customer_note", "orders"."merchant_note", "orders"."currency", "orders"."postal_first_name", "orders"."postal_last_name", "orders"."merchant_name", "orders"."state_code", "orders"."fulfillment_status", "orders"."tags", "orders"."origin_admin_url", "orders"."imported_at", "orders"."shop_updated_at", "orders"."disable_address_sync", "orders"."status_changed_at", "orders"."internal_issues", "orders"."external_issues", "orders"."mondial_relay_id", "orders"."mondial_relay_zip", "orders"."order_type", "orders"."returns_count", "orders"."manual_order", "orders"."recipient_instructions", "orders"."customer_facing_order_name", "orders"."prioritized", "orders"."merchant_custom_barcode", "orders"."merchant_custom_text", "orders"."merchant_custom_qrcode", "orders"."total_outstanding_in_cents", "orders"."shipping_cost_in_cents", "orders"."uuid", "orders"."external_id", "orders"."external_order_name", "orders"."latest_ship_date", "orders"."latest_delivery_date", "orders"."merchant_custom_packaging", "orders"."merchant_note_updated_at", "orders"."metadata", "orders"."initial_status_reason", "orders"."presentment_currency", "orders"."external_refund_ids", "orders"."presentment_shipping_cost_in_cents", "orders"."external_payment_processed_at", "orders"."warehouse_allocated", "orders"."marketplace_id", "orders"."marketplace_identification_rule_id", "orders"."total_tax_in_cents", "orders"."custom_metadata", "orders"."marketplace_order_name", "orders"."created_by_user_id", "orders"."buyer_vat_number" FROM "orders" WHERE "orders"."deleted_at" IS NULL AND "orders"."id" = 1164361
D, [2025-04-06T15:14:19.243529 #28843] DEBUG -- : Dx::ReturnLabel Load (1.9ms) SELECT "dx_return_labels"."id", "dx_return_labels"."external_id", "dx_return_labels"."response_payload", "dx_return_labels"."request_payload", "dx_return_labels"."label_provider", "dx_return_labels"."return_delivery_method_id", "dx_return_labels"."return_id", "dx_return_labels"."created_at", "dx_return_labels"."updated_at", "dx_return_labels"."external_account_id", "dx_return_labels"."uuid", "dx_return_labels"."related_shipment_id", "dx_return_labels"."tracking_code" FROM "dx_return_labels" WHERE "dx_return_labels"."return_id" = 1078
D, [2025-04-06T15:14:19.255373 #28843] DEBUG -- : Ox::ReturnLineItem Load (1.5ms) SELECT "return_line_items"."id", "return_line_items"."return_id", "return_line_items"."sku_id", "return_line_items"."inventory_batch_id", "return_line_items"."return_item_id", "return_line_items"."condition", "return_line_items"."follow_up_action", "return_line_items"."created_at", "return_line_items"."updated_at", "return_line_items"."basket_allocation_id" FROM "return_line_items" WHERE "return_line_items"."return_id" = 1078
D, [2025-04-06T15:14:19.258361 #28843] DEBUG -- : ReturnRequestConditionCheck Load (1.4ms) SELECT "return_request_condition_checks"."id", "return_request_condition_checks"."return_id", "return_request_condition_checks"."return_request_condition_id", "return_request_condition_checks"."condition_met", "return_request_condition_checks"."actual_values", "return_request_condition_checks"."created_at", "return_request_condition_checks"."updated_at" FROM "return_request_condition_checks" WHERE "return_request_condition_checks"."return_id" = 1078
D, [2025-04-06T15:14:19.274044 #28843] DEBUG -- : Shipment Load (3.2ms) SELECT "shipments"."id", "shipments"."order_id", "shipments"."tracking_code", "shipments"."status", "shipments"."created_at", "shipments"."updated_at", "shipments"."weight", "shipments"."deleted_at", "shipments"."shipped_at", "shipments"."option_title", "shipments"."shipping_contracts_methods_merchant_id", "shipments"."shipping_contracts_method_id", "shipments"."cutoff_at", "shipments"."ready_for_fulfillment_at", "shipments"."rules_overwritten", "shipments"."status_changed_at", "shipments"."internal_issues", "shipments"."external_issues", "shipments"."split_from_shipment_id", "shipments"."warehouse_id", "shipments"."split_reason", "shipments"."split_by_user_id", "shipments"."split_note", "shipments"."bulk_picking", "shipments"."packing_slip_data", "shipments"."expected_fulfillment_at", "shipments"."expected_shipping_contracts_method_id", "shipments"."expected_weight", "shipments"."expected_packaging_sku_id", "shipments"."started_picking_at", "shipments"."finished_picking_at", "shipments"."started_packing_at", "shipments"."finished_packing_at", "shipments"."expected_cutoff_at", "shipments"."effective_weight", "shipments"."ox_daily_carrier_pickup_id", "shipments"."delivered_at", "shipments"."days_shipped_to_delivered", "shipments"."send_in_basket", "shipments"."not_enough_stock", "shipments"."pallete_delivery_cost", "shipments"."delivery_status", "shipments"."calculated_weight_in_kg", "shipments"."needs_manual_weight", "shipments"."merchant_id", "shipments"."shipped_with_jid", "shipments"."needs_manual_weight_for_qa", "shipments"."weight_error_term", "shipments"."external_fulfillment_id", "shipments"."manual_weight_reason", "shipments"."logistics_provider_id", "shipments"."packaging_longest", "shipments"."packaging_medium", "shipments"."packaging_shortest", "shipments"."uuid", "shipments"."pickable_skus_count", "shipments"."requires_customs_cache", "shipments"."default_packaging_use_id", "shipments"."marketplace_id", "shipments"."prioritized", "shipments"."order_created_at", "shipments"."pickable_items_count", "shipments"."requested_shipping_contracts_method_id", "shipments"."bulk_packing_parent_shipment_id", "shipments"."bulk_packing_v2_started", "shipments"."expected_contract_method_unreliable_reason", "shipments"."bulk_packing_width_in_mm", "shipments"."bulk_packing_height_in_mm", "shipments"."bulk_packing_length_in_mm" FROM "shipments" WHERE "shipments"."deleted_at" IS NULL AND "shipments"."order_id" = 1164361
D, [2025-04-06T15:14:19.324536 #28843] DEBUG -- : Dx::ReturnEvent Load (1.5ms) SELECT "dx_return_events"."id", "dx_return_events"."external_created_at", "dx_return_events"."external_received_at", "dx_return_events"."original_status", "dx_return_events"."status", "dx_return_events"."received_from", "dx_return_events"."dx_return_label_id", "dx_return_events"."created_at", "dx_return_events"."updated_at" FROM "dx_return_events" WHERE "dx_return_events"."dx_return_label_id" = 234
D, [2025-04-06T15:14:19.334252 #28843] DEBUG -- : ReturnRequestCondition Load (2.0ms) SELECT "return_request_conditions"."id", "return_request_conditions"."operator", "return_request_conditions"."target_field", "return_request_conditions"."values", "return_request_conditions"."branding_id", "return_request_conditions"."deleted_at", "return_request_conditions"."created_at", "return_request_conditions"."updated_at" FROM "return_request_conditions" WHERE "return_request_conditions"."id" IN (105, 106)
D, [2025-04-06T15:14:19.346883 #28843] DEBUG -- : ShipmentItem Load (2.0ms) SELECT "shipment_items"."id", "shipment_items"."shipment_id", "shipment_items"."created_at", "shipment_items"."updated_at", "shipment_items"."deleted_at", "shipment_items"."quantity", "shipment_items"."confirmed", "shipment_items"."sku_id", "shipment_items"."internal_issues", "shipment_items"."external_issues", "shipment_items"."total_sku_quantity", "shipment_items"."customise", "shipment_items"."external_id", "shipment_items"."needs_reshuffling_issue", "shipment_items"."new_sku_issue", "shipment_items"."out_of_stock_issue", "shipment_items"."not_enough_stock", "shipment_items"."parent_sku_id", "shipment_items"."packaging_rule_sku_id", "shipment_items"."skip_fulfillment", "shipment_items"."insertion_strategy", "shipment_items"."skip_fulfillment_reason", "shipment_items"."price_per_unit_in_cents", "shipment_items"."price_per_unit_in_cents_with_discount", "shipment_items"."cost_per_unit_in_cents", "shipment_items"."inventory_batch_ids", "shipment_items"."presentment_price_per_unit_in_cents_with_discount", "shipment_items"."stock_issues_caused_by_batch_selection", "shipment_items"."not_enough_pickable_stock", "shipment_items"."presentment_price_per_unit_in_cents" FROM "shipment_items" WHERE "shipment_items"."deleted_at" IS NULL AND "shipment_items"."shipment_id" = 652037
D, [2025-04-06T15:14:19.371193 #28843] DEBUG -- : Sku Load (2.5ms) SELECT "skus"."id", "skus"."merchant_sku", "skus"."name", "skus"."shop_depth", "skus"."shop_photo", "skus"."status", "skus"."tag1", "skus"."tag2", "skus"."tag3", "skus"."fulfilled_by", "skus"."created_at", "skus"."updated_at", "skus"."image_data", "skus"."box_image_data", "skus"."lead_time_in_days", "skus"."extension_definition_type", "skus"."extension_definition_id", "skus"."sku_type", "skus"."cost", "skus"."country_code_of_origin", "skus"."hs_code", "skus"."barcode", "skus"."merchant_id", "skus"."verified", "skus"."sync_source_shop_sku_id", "skus"."internal_barcode", "skus"."available_to_all_merchants", "skus"."identification_requirement", "skus"."alternative_barcode", "skus"."vendor", "skus"."weight_in_kg", "skus"."longest", "skus"."medium", "skus"."shortest", "skus"."procured_by_hive", "skus"."customisable", "skus"."send_individually", "skus"."batch_tracking_enabled", "skus"."shop_weight_in_kg", "skus"."bio_certified", "skus"."shop_hs_code", "skus"."shop_cost", "skus"."shop_country_code_of_origin", "skus"."measured_weights_count", "skus"."weight_standard_deviation_in_kg", "skus"."weight_standard_error_in_kg", "skus"."mean_weight_in_kg", "skus"."inventory_minimum", "skus"."vat_rate", "skus"."uid", "skus"."box_category", "skus"."inner_longest", "skus"."inner_medium", "skus"."inner_shortest", "skus"."serial_number_tracking_enabled", "skus"."track_serial_numbers_in", "skus"."imported_shop_photo_data", "skus"."return_policy_in_days", "skus"."strict_serial_number_tracking", "skus"."b2c_shelf_life_in_weeks", "skus"."b2b_shelf_life_in_weeks", "skus"."ito_shelf_life_in_weeks", "skus"."kit_shelf_life_in_weeks", "skus"."dangerous", "skus"."un_number", "skus"."fc_notes", "skus"."send_in_own_packaging", "skus"."dummy_filling_material", "skus"."base_sku_id", "skus"."items_per_case", "skus"."created_by_id" FROM "skus" WHERE "skus"."id" = 123123
------------------------------- TRIGGERING QUERY -------------------------------
=>
{approved_by_user_name: "Francesco Mari",
cancelled_by_user_name: "internaluser dojo staging",
return_request_condition_checks:
[{condition_met: false,
actual_values: ["3"],
return_request_condition: {target_field: "customer_orders_count", operator: "greater_than", values: ["4"], deleted_at: nil}},
{condition_met: true,
actual_values: ["800"],
return_request_condition: {target_field: "total_ordered_items_price", operator: "greater_than", values: ["600"], deleted_at: nil}}]}
# users table queries N times (before triggering the query)
# Return.find(1078).update(request_approved_by: User.find(787), request_cancelled_by: User.find(783))
# branding_id = 242
# return_id = 1078
# return_request_condition_id_1 = 105
# return_request_condition_id_2 = 106
# ReturnRequestConditionCheck.create!(return_id: 1078, return_request_condition_id: 105, condition_met: false, actual_values: ["3"])
# ReturnRequestConditionCheck.create!(return_id: 1078, return_request_condition_id: 106, condition_met: true, actual_values: ["800"])
ActiveRecord::Base.logger = Logger.new(STDOUT)
class Return < ApplicationRecord
belongs_to :request_approved_by, optional: true, class_name: "User"
belongs_to :request_cancelled_by, optional: true, class_name: "User"
end
merchant = Merchant.find 130
return_id = 1078
return_record = merchant.returns.includes(
# :request_approved_by,
# :request_cancelled_by,
order: {shipment_items: [:sku]},
return_label: [:return_events],
return_line_items: [:photos, :sku],
return_request_condition_checks: [:return_request_condition]
).find(return_id)
puts "------------------------------- TRIGGERING QUERY -------------------------------"
{
approved_by_user_name: return_record.request_approved_by&.name,
cancelled_by_user_name: return_record.request_cancelled_by&.name,
return_request_condition_checks: return_record.return_request_condition_checks.map do |rrcc|
{
condition_met: rrcc.condition_met,
actual_values: rrcc.actual_values,
return_request_condition: {
target_field: rrcc.return_request_condition.target_field,
operator: rrcc.return_request_condition.operator,
values: rrcc.return_request_condition.values,
deleted_at: rrcc.return_request_condition.deleted_at&.utc&.iso8601(3)
}
}
end
}
D, [2025-04-06T15:10:34.771067 #28772] DEBUG -- : ActiveRecord::SchemaMigration Load (8.6ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
D, [2025-04-06T15:10:34.813273 #28772] DEBUG -- : Merchant Load (3.5ms) SELECT "merchants"."id", "merchants"."name", "merchants"."contact_email", "merchants"."phone", "merchants"."country", "merchants"."city", "merchants"."state", "merchants"."postal_code", "merchants"."street1", "merchants"."street2", "merchants"."logo", "merchants"."return_policy", "merchants"."packaging_preference", "merchants"."payment_details", "merchants"."test_account", "merchants"."created_at", "merchants"."updated_at", "merchants"."postal_name", "merchants"."billing_address_postal_name", "merchants"."billing_address_country", "merchants"."billing_address_city", "merchants"."billing_address_state", "merchants"."billing_address_postal_code", "merchants"."billing_address_street1", "merchants"."billing_address_street2", "merchants"."deleted_at", "merchants"."image_data", "merchants"."contract_signing_date", "merchants"."active", "merchants"."billing_notes", "merchants"."payments_goal_in_days", "merchants"."shipping_contract_id", "merchants"."agreed_cut_off_time", "merchants"."throughput", "merchants"."multishop_enabled", "merchants"."merchant_shipments_enabled", "merchants"."sku_confirmation_rule", "merchants"."street", "merchants"."house_number", "merchants"."shipping_contracts_methods_merchant_id", "merchants"."finance_currency_id", "merchants"."packaging_guidelines_url", "merchants"."block_inventory_for_older_orders", "merchants"."registration_court_and_number", "merchants"."managing_directors", "merchants"."uuid", "merchants"."percentage_weight_buffer", "merchants"."shipments_need_manual_weight", "merchants"."qa_check_interval", "merchants"."inventory_minimum", "merchants"."require_manual_sku_weight_confirmation", "merchants"."bulk_picking_limit", "merchants"."max_automatic_shipment_weight_threshold_in_kg", "merchants"."fulfillment_setup", "merchants"."max_filler_material_weight_kg", "merchants"."eori_number", "merchants"."lucid_number", "merchants"."preferred_currency", "merchants"."main_vat_number", "merchants"."billing_emails", "merchants"."preferred_payment_method", "merchants"."vat_numbers", "merchants"."joined_delivery_predictions_waitlist", "merchants"."in_onboarding", "merchants"."serial_number_tracking_enabled", "merchants"."cart_picking_enabled", "merchants"."batch_tracking_enabled", "merchants"."delivery_and_allocations_flow_enabled", "merchants"."delivery_and_allocations_flow_available", "merchants"."uk_eori_number", "merchants"."hide_onboarding", "merchants"."sepa_document_data", "merchants"."bdo_number", "merchants"."lucid_pdf_data", "merchants"."using_two_sendcloud_accounts", "merchants"."invoicing_period", "merchants"."automatic_sku_confirmation_method_change_disabled", "merchants"."box_specific_rules_activated_at", "merchants"."packaging_settings_activated_at", "merchants"."show_packaging_guidelines_url_in_hive_app", "merchants"."tier_id", "merchants"."batch_management_enabled", "merchants"."iban", "merchants"."bic", "merchants"."edd_feature_flag_enabled", "merchants"."skip_invoicing_for_custom_outer_packaging", "merchants"."skip_invoicing_for_custom_filling_material", "merchants"."ioss_number", "merchants"."weight_check_z_index_score", "merchants"."allowed_service_bundles", "merchants"."contractual_start_date", "merchants"."returns_approval_feature_flag" FROM "merchants" WHERE "merchants"."id" = 130 LIMIT 1
D, [2025-04-06T15:10:34.956546 #28772] DEBUG -- : Return Load (3.4ms) SELECT "returns"."id", "returns"."order_id", "returns"."status", "returns"."return_reason", "returns"."product_condition", "returns"."merchant_guidance", "returns"."items_returned", "returns"."received_at", "returns"."created_at", "returns"."updated_at", "returns"."image_data", "returns"."created_by_id", "returns"."notes", "returns"."return_box_id", "returns"."merchant_notes", "returns"."weight_in_kg", "returns"."tracking_code", "returns"."shipping_contracts_method_id", "returns"."customer_return_reason", "returns"."warehouse_id", "returns"."settlement_option", "returns"."mx_notified", "returns"."deleted_at", "returns"."created_via", "returns"."started_processing_at", "returns"."started_processing_by_id", "returns"."completed_handling_at", "returns"."completed_handling_by_id", "returns"."return_reason_type", "returns"."reviewed", "returns"."return_delivery_method_id", "returns"."external_refund_id", "returns"."manually_marked_as_refunded", "returns"."refund_completed_by_id", "returns"."refund_completed_at", "returns"."refunded_amount_in_cents", "returns"."external_gift_card_id", "returns"."refunded_currency", "returns"."shop_id", "returns"."all_returns_were_requiring_request", "returns"."request_approved_by_id", "returns"."request_approved_at", "returns"."request_cancelled_by_id", "returns"."request_cancelled_at", "returns"."request_cancelled_description" FROM "returns" INNER JOIN "shops" ON "returns"."shop_id" = "shops"."id" WHERE "returns"."deleted_at" IS NULL AND "shops"."deleted_at" IS NULL AND "shops"."merchant_id" = 130 AND "returns"."id" = 1078 LIMIT 1
D, [2025-04-06T15:10:34.999825 #28772] DEBUG -- : Order Load (3.0ms) SELECT "orders"."id", "orders"."shop_id", "orders"."customer_id", "orders"."platform_order_id", "orders"."postal_name", "orders"."service_fee", "orders"."estimated_delivery_date", "orders"."created_at", "orders"."updated_at", "orders"."name", "orders"."internal_status", "orders"."deleted_at", "orders"."payment_method", "orders"."financial_status", "orders"."customer_language", "orders"."total_amount", "orders"."customer_note", "orders"."merchant_note", "orders"."currency", "orders"."postal_first_name", "orders"."postal_last_name", "orders"."merchant_name", "orders"."state_code", "orders"."fulfillment_status", "orders"."tags", "orders"."origin_admin_url", "orders"."imported_at", "orders"."shop_updated_at", "orders"."disable_address_sync", "orders"."status_changed_at", "orders"."internal_issues", "orders"."external_issues", "orders"."mondial_relay_id", "orders"."mondial_relay_zip", "orders"."order_type", "orders"."returns_count", "orders"."manual_order", "orders"."recipient_instructions", "orders"."customer_facing_order_name", "orders"."prioritized", "orders"."merchant_custom_barcode", "orders"."merchant_custom_text", "orders"."merchant_custom_qrcode", "orders"."total_outstanding_in_cents", "orders"."shipping_cost_in_cents", "orders"."uuid", "orders"."external_id", "orders"."external_order_name", "orders"."latest_ship_date", "orders"."latest_delivery_date", "orders"."merchant_custom_packaging", "orders"."merchant_note_updated_at", "orders"."metadata", "orders"."initial_status_reason", "orders"."presentment_currency", "orders"."external_refund_ids", "orders"."presentment_shipping_cost_in_cents", "orders"."external_payment_processed_at", "orders"."warehouse_allocated", "orders"."marketplace_id", "orders"."marketplace_identification_rule_id", "orders"."total_tax_in_cents", "orders"."custom_metadata", "orders"."marketplace_order_name", "orders"."created_by_user_id", "orders"."buyer_vat_number" FROM "orders" WHERE "orders"."deleted_at" IS NULL AND "orders"."id" = 1164361
D, [2025-04-06T15:10:35.056876 #28772] DEBUG -- : Dx::ReturnLabel Load (2.5ms) SELECT "dx_return_labels"."id", "dx_return_labels"."external_id", "dx_return_labels"."response_payload", "dx_return_labels"."request_payload", "dx_return_labels"."label_provider", "dx_return_labels"."return_delivery_method_id", "dx_return_labels"."return_id", "dx_return_labels"."created_at", "dx_return_labels"."updated_at", "dx_return_labels"."external_account_id", "dx_return_labels"."uuid", "dx_return_labels"."related_shipment_id", "dx_return_labels"."tracking_code" FROM "dx_return_labels" WHERE "dx_return_labels"."return_id" = 1078
D, [2025-04-06T15:10:35.078846 #28772] DEBUG -- : Ox::ReturnLineItem Load (2.4ms) SELECT "return_line_items"."id", "return_line_items"."return_id", "return_line_items"."sku_id", "return_line_items"."inventory_batch_id", "return_line_items"."return_item_id", "return_line_items"."condition", "return_line_items"."follow_up_action", "return_line_items"."created_at", "return_line_items"."updated_at", "return_line_items"."basket_allocation_id" FROM "return_line_items" WHERE "return_line_items"."return_id" = 1078
D, [2025-04-06T15:10:35.083573 #28772] DEBUG -- : ReturnRequestConditionCheck Load (1.5ms) SELECT "return_request_condition_checks"."id", "return_request_condition_checks"."return_id", "return_request_condition_checks"."return_request_condition_id", "return_request_condition_checks"."condition_met", "return_request_condition_checks"."actual_values", "return_request_condition_checks"."created_at", "return_request_condition_checks"."updated_at" FROM "return_request_condition_checks" WHERE "return_request_condition_checks"."return_id" = 1078
D, [2025-04-06T15:10:35.105518 #28772] DEBUG -- : Shipment Load (3.4ms) SELECT "shipments"."id", "shipments"."order_id", "shipments"."tracking_code", "shipments"."status", "shipments"."created_at", "shipments"."updated_at", "shipments"."weight", "shipments"."deleted_at", "shipments"."shipped_at", "shipments"."option_title", "shipments"."shipping_contracts_methods_merchant_id", "shipments"."shipping_contracts_method_id", "shipments"."cutoff_at", "shipments"."ready_for_fulfillment_at", "shipments"."rules_overwritten", "shipments"."status_changed_at", "shipments"."internal_issues", "shipments"."external_issues", "shipments"."split_from_shipment_id", "shipments"."warehouse_id", "shipments"."split_reason", "shipments"."split_by_user_id", "shipments"."split_note", "shipments"."bulk_picking", "shipments"."packing_slip_data", "shipments"."expected_fulfillment_at", "shipments"."expected_shipping_contracts_method_id", "shipments"."expected_weight", "shipments"."expected_packaging_sku_id", "shipments"."started_picking_at", "shipments"."finished_picking_at", "shipments"."started_packing_at", "shipments"."finished_packing_at", "shipments"."expected_cutoff_at", "shipments"."effective_weight", "shipments"."ox_daily_carrier_pickup_id", "shipments"."delivered_at", "shipments"."days_shipped_to_delivered", "shipments"."send_in_basket", "shipments"."not_enough_stock", "shipments"."pallete_delivery_cost", "shipments"."delivery_status", "shipments"."calculated_weight_in_kg", "shipments"."needs_manual_weight", "shipments"."merchant_id", "shipments"."shipped_with_jid", "shipments"."needs_manual_weight_for_qa", "shipments"."weight_error_term", "shipments"."external_fulfillment_id", "shipments"."manual_weight_reason", "shipments"."logistics_provider_id", "shipments"."packaging_longest", "shipments"."packaging_medium", "shipments"."packaging_shortest", "shipments"."uuid", "shipments"."pickable_skus_count", "shipments"."requires_customs_cache", "shipments"."default_packaging_use_id", "shipments"."marketplace_id", "shipments"."prioritized", "shipments"."order_created_at", "shipments"."pickable_items_count", "shipments"."requested_shipping_contracts_method_id", "shipments"."bulk_packing_parent_shipment_id", "shipments"."bulk_packing_v2_started", "shipments"."expected_contract_method_unreliable_reason", "shipments"."bulk_packing_width_in_mm", "shipments"."bulk_packing_height_in_mm", "shipments"."bulk_packing_length_in_mm" FROM "shipments" WHERE "shipments"."deleted_at" IS NULL AND "shipments"."order_id" = 1164361
D, [2025-04-06T15:10:35.158006 #28772] DEBUG -- : Dx::ReturnEvent Load (1.6ms) SELECT "dx_return_events"."id", "dx_return_events"."external_created_at", "dx_return_events"."external_received_at", "dx_return_events"."original_status", "dx_return_events"."status", "dx_return_events"."received_from", "dx_return_events"."dx_return_label_id", "dx_return_events"."created_at", "dx_return_events"."updated_at" FROM "dx_return_events" WHERE "dx_return_events"."dx_return_label_id" = 234
D, [2025-04-06T15:10:35.169402 #28772] DEBUG -- : ReturnRequestCondition Load (1.5ms) SELECT "return_request_conditions"."id", "return_request_conditions"."operator", "return_request_conditions"."target_field", "return_request_conditions"."values", "return_request_conditions"."branding_id", "return_request_conditions"."deleted_at", "return_request_conditions"."created_at", "return_request_conditions"."updated_at" FROM "return_request_conditions" WHERE "return_request_conditions"."id" IN (105, 106)
D, [2025-04-06T15:10:35.183093 #28772] DEBUG -- : ShipmentItem Load (4.5ms) SELECT "shipment_items"."id", "shipment_items"."shipment_id", "shipment_items"."created_at", "shipment_items"."updated_at", "shipment_items"."deleted_at", "shipment_items"."quantity", "shipment_items"."confirmed", "shipment_items"."sku_id", "shipment_items"."internal_issues", "shipment_items"."external_issues", "shipment_items"."total_sku_quantity", "shipment_items"."customise", "shipment_items"."external_id", "shipment_items"."needs_reshuffling_issue", "shipment_items"."new_sku_issue", "shipment_items"."out_of_stock_issue", "shipment_items"."not_enough_stock", "shipment_items"."parent_sku_id", "shipment_items"."packaging_rule_sku_id", "shipment_items"."skip_fulfillment", "shipment_items"."insertion_strategy", "shipment_items"."skip_fulfillment_reason", "shipment_items"."price_per_unit_in_cents", "shipment_items"."price_per_unit_in_cents_with_discount", "shipment_items"."cost_per_unit_in_cents", "shipment_items"."inventory_batch_ids", "shipment_items"."presentment_price_per_unit_in_cents_with_discount", "shipment_items"."stock_issues_caused_by_batch_selection", "shipment_items"."not_enough_pickable_stock", "shipment_items"."presentment_price_per_unit_in_cents" FROM "shipment_items" WHERE "shipment_items"."deleted_at" IS NULL AND "shipment_items"."shipment_id" = 652037
D, [2025-04-06T15:10:35.247521 #28772] DEBUG -- : Sku Load (2.6ms) SELECT "skus"."id", "skus"."merchant_sku", "skus"."name", "skus"."shop_depth", "skus"."shop_photo", "skus"."status", "skus"."tag1", "skus"."tag2", "skus"."tag3", "skus"."fulfilled_by", "skus"."created_at", "skus"."updated_at", "skus"."image_data", "skus"."box_image_data", "skus"."lead_time_in_days", "skus"."extension_definition_type", "skus"."extension_definition_id", "skus"."sku_type", "skus"."cost", "skus"."country_code_of_origin", "skus"."hs_code", "skus"."barcode", "skus"."merchant_id", "skus"."verified", "skus"."sync_source_shop_sku_id", "skus"."internal_barcode", "skus"."available_to_all_merchants", "skus"."identification_requirement", "skus"."alternative_barcode", "skus"."vendor", "skus"."weight_in_kg", "skus"."longest", "skus"."medium", "skus"."shortest", "skus"."procured_by_hive", "skus"."customisable", "skus"."send_individually", "skus"."batch_tracking_enabled", "skus"."shop_weight_in_kg", "skus"."bio_certified", "skus"."shop_hs_code", "skus"."shop_cost", "skus"."shop_country_code_of_origin", "skus"."measured_weights_count", "skus"."weight_standard_deviation_in_kg", "skus"."weight_standard_error_in_kg", "skus"."mean_weight_in_kg", "skus"."inventory_minimum", "skus"."vat_rate", "skus"."uid", "skus"."box_category", "skus"."inner_longest", "skus"."inner_medium", "skus"."inner_shortest", "skus"."serial_number_tracking_enabled", "skus"."track_serial_numbers_in", "skus"."imported_shop_photo_data", "skus"."return_policy_in_days", "skus"."strict_serial_number_tracking", "skus"."b2c_shelf_life_in_weeks", "skus"."b2b_shelf_life_in_weeks", "skus"."ito_shelf_life_in_weeks", "skus"."kit_shelf_life_in_weeks", "skus"."dangerous", "skus"."un_number", "skus"."fc_notes", "skus"."send_in_own_packaging", "skus"."dummy_filling_material", "skus"."base_sku_id", "skus"."items_per_case", "skus"."created_by_id" FROM "skus" WHERE "skus"."id" = 123123
------------------------------- TRIGGERING QUERY -------------------------------
D, [2025-04-06T15:10:35.307423 #28772] DEBUG -- : User Load (3.5ms) SELECT "users"."id", "users"."created_at", "users"."updated_at", "users"."email", "users"."encrypted_password", "users"."reset_password_token", "users"."reset_password_sent_at", "users"."remember_created_at", "users"."sign_in_count", "users"."current_sign_in_at", "users"."last_sign_in_at", "users"."current_sign_in_ip", "users"."last_sign_in_ip", "users"."provider", "users"."uid", "users"."confirmation_token", "users"."confirmed_at", "users"."confirmation_sent_at", "users"."phone", "users"."full_name", "users"."unconfirmed_email", "users"."token", "users"."admin_role", "users"."warehouse_manager_role", "users"."warehouse_worker_role", "users"."merchant_role", "users"."deleted_at", "users"."image_data", "users"."auth_token", "users"."shyftplan_punch_token", "users"."shyftplan_staff_number", "users"."token_expiry", "users"."super_admin_role", "users"."logistics_provider_id", "users"."deactivated_at", "users"."role_permission_id", "users"."mx_role_id" FROM "users" WHERE "users"."id" = 787 LIMIT 1
D, [2025-04-06T15:10:35.351352 #28772] DEBUG -- : User Load (1.7ms) SELECT "users"."id", "users"."created_at", "users"."updated_at", "users"."email", "users"."encrypted_password", "users"."reset_password_token", "users"."reset_password_sent_at", "users"."remember_created_at", "users"."sign_in_count", "users"."current_sign_in_at", "users"."last_sign_in_at", "users"."current_sign_in_ip", "users"."last_sign_in_ip", "users"."provider", "users"."uid", "users"."confirmation_token", "users"."confirmed_at", "users"."confirmation_sent_at", "users"."phone", "users"."full_name", "users"."unconfirmed_email", "users"."token", "users"."admin_role", "users"."warehouse_manager_role", "users"."warehouse_worker_role", "users"."merchant_role", "users"."deleted_at", "users"."image_data", "users"."auth_token", "users"."shyftplan_punch_token", "users"."shyftplan_staff_number", "users"."token_expiry", "users"."super_admin_role", "users"."logistics_provider_id", "users"."deactivated_at", "users"."role_permission_id", "users"."mx_role_id" FROM "users" WHERE "users"."id" = 783 LIMIT 1
=>
{approved_by_user_name: "Francesco Mari",
cancelled_by_user_name: "internaluser dojo staging",
return_request_condition_checks:
[{condition_met: false,
actual_values: ["3"],
return_request_condition: {target_field: "customer_orders_count", operator: "greater_than", values: ["4"], deleted_at: nil}},
{condition_met: true,
actual_values: ["800"],
return_request_condition: {target_field: "total_ordered_items_price", operator: "greater_than", values: ["600"], deleted_at: nil}}]}
# users table queried N times (when triggering the query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment