Skip to content

Instantly share code, notes, and snippets.

@rclements
Created June 30, 2011 21:41
Show Gist options
  • Save rclements/1057319 to your computer and use it in GitHub Desktop.
Save rclements/1057319 to your computer and use it in GitHub Desktop.
This is the Cat_Vehicle:
=> [#<CatVehicle Vehicle_Key: "2008~5~21~9", Vehicle_Year: "2008", Vehicle_Make: "CHEVROLET", Vehicle_Model: "COBALT", Vehicle_Engine: "4-134 2.2L DOHC", Vehicle_Id: 0>]
This is the Cat_Product:
=> #<CatProduct Product_Key: "2008~5~21~9", Product_Cat: "Electrical", Product_Group: "Alternators & Generators", Product_Part: "15828450", Product_Mfg: "ACD", Product_Desc: "NEW ALTERNATOR", Product_Xtd_Desc: "New Alternator", Product_Comments: "115 AMP GEN(K64)", Product_Special: "">
The two should have a PartNumberVehicleLink to connect the two via the VehiclePartImporter
This is the Vehicle that should be found that matches the Cat_Vehicle:
=> #<Vehicle id: 36334, make_id: "5", model_id: "21", year_id: "2008", engine_id: "9", customer_id: nil, si_client_id: nil, created_at: "2010-12-05 06:24:58", updated_at: "2010-12-05 06:24:58", make_name: "CHEVROLET", model_name: "COBALT", engine_name: "4-134 2.2L DOHC", vin: nil, canonical: true>
This is the importer that runs:
def run
CatProduct.find_in_batches(:batch_size => 100) do |products|
GC.start
products.each do |cp|
@category = PnCategory.find_or_create_by_name(cp.Product_Cat)
@subcategory = PnCategory.find_or_create_by_name(:name => cp.Product_Group, :parent_id => @category.id)
@part_number = PartNumber.find_or_create_by_number_and_line_code(:number => cp.Product_Part, :line_code => cp.Product_Mfg)
@part_number.update_attributes(:full_description => cp.Product_Xtd_Desc, :name => cp.Product_Desc)
@category_part_number_link = CategoryPartNumberLink.find_or_create_by_part_number_id_and_pn_category_id(:part_number_id => @part_number.id, :pn_category_id => @subcategory.id)
@matched_vehicle = CatVehicle.find_by_Vehicle_Key(cp.Product_Key)
@vehicle = Vehicle.find_or_create_by_year_id_and_make_name_and_model_name_and_engine_name_and_canonical(:year_id => @matched_vehicle.Vehicle_Year, :make_name => @matched_vehicle.Vehicle_Make, :model_name => @matched_vehicle.Vehicle_Model, :engine_name => @matched_vehicle.Vehicle_Engine, :canonical => true)
PartNumberVehicleLink.find_or_create_by_vehicle_id_and_part_number_id(:vehicle_id => @vehicle.id, :part_number_id => @part_number.id)
@success_count += 1
end
end
puts "--------SUCCESS: #{@success_count}-------FAILED: #{@errors.count}--------"
end
The PartNumber is never found or created and the link doesn't exist. When I removed Cat_Product.find_in_batches and specified the Cat_Product, it created the link successfully.
This appears to be happening in several cases. Can you please tell me what is being done wrong here. Adam D., James and Nick have all had their eyes on this and this it's still an issue. HELP!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment