@@ -12,7 +12,7 @@ module FinderMethods
1212 def find ( id , loader : default_loader )
1313 gid = URI ::GID . build ( app : "shopify" , model_name : model_name . name . demodulize , model_id : id )
1414 model_type = name . demodulize
15- attributes = loader . load_attributes ( gid , model_type )
15+ attributes = loader . load_attributes ( model_type , gid )
1616
1717 return nil if attributes . nil?
1818
@@ -35,6 +35,48 @@ def default_loader=(loader)
3535 @default_loader = loader
3636 end
3737
38+ # Query for multiple records using attribute conditions
39+ # @param conditions [Hash] The conditions to query (e.g., { email: "example@test.com", first_name: "John" })
40+ # @param options [Hash] Options hash containing loader and limit (when first arg is a Hash)
41+ # @option options [ActiveShopifyGraphQL::Loader] :loader The loader to use for fetching data
42+ # @option options [Integer] :limit The maximum number of records to return (default: 250, max: 250)
43+ # @return [Array<Object>] Array of model instances
44+ # @raise [ArgumentError] If any attribute is not valid for querying
45+ #
46+ # @example
47+ # # Keyword argument style (recommended)
48+ # Customer.where(email: "john@example.com")
49+ # Customer.where(first_name: "John", country: "Canada")
50+ # Customer.where(orders_count: { gte: 5 })
51+ # Customer.where(created_at: { gte: "2024-01-01", lt: "2024-02-01" })
52+ #
53+ # # Hash style with options
54+ # Customer.where({ email: "john@example.com" }, loader: custom_loader, limit: 100)
55+ def where ( conditions_or_first_condition = { } , *args , **options )
56+ # Handle both syntaxes:
57+ # where(email: "john@example.com") - keyword args become options
58+ # where({ email: "john@example.com" }, loader: custom_loader) - explicit hash + options
59+ if conditions_or_first_condition . is_a? ( Hash ) && !conditions_or_first_condition . empty?
60+ # Explicit hash provided as first argument
61+ conditions = conditions_or_first_condition
62+ # Any additional options passed as keyword args or second hash argument
63+ final_options = args . first . is_a? ( Hash ) ? options . merge ( args . first ) : options
64+ else
65+ # Keyword arguments style - conditions come from options, excluding known option keys
66+ known_option_keys = %i[ loader limit ]
67+ conditions = options . except ( *known_option_keys )
68+ final_options = options . slice ( *known_option_keys )
69+ end
70+
71+ loader = final_options [ :loader ] || default_loader
72+ limit = final_options [ :limit ] || 250
73+
74+ model_type = name . demodulize
75+ attributes_array = loader . load_collection ( model_type , conditions , limit : limit )
76+
77+ attributes_array . map { |attributes | new ( attributes ) }
78+ end
79+
3880 private
3981
4082 # Infers the loader class name from the model name
0 commit comments