0
我只想返回查詢中的某些字段。如何從shopify gem api查詢獲得特定字段
例如:
ShopifyAPI::Metafield.find(:all,:params=>{:resource => "products"},:fields=>['value'])
我只是想從metafield對象返回值字段
我只想返回查詢中的某些字段。如何從shopify gem api查詢獲得特定字段
例如:
ShopifyAPI::Metafield.find(:all,:params=>{:resource => "products"},:fields=>['value'])
我只是想從metafield對象返回值字段
你差點。您忘記實際提供資源的ID。就你而言,因爲你正在尋找分配給產品的元字段的所有值,所以你需要提供產品ID。
ShopifyAPI::Metafield.all(params: {resource: 'products', resource_id: 149523945, fields: 'value'})
=> [
#<ShopifyAPI::Metafield:0x007f80041f3958 @attributes={"value"=>"4999"}, @prefix_options={:resource=>"products", :resource_id=>149523945}, @persisted=true>,
#<ShopifyAPI::Metafield:0x007f80041f36b0 @attributes={"value"=>"Céà"}, @prefix_options={:resource=>"products", :resource_id=>149523945}, @persisted=true>,
#<ShopifyAPI::Metafield:0x007f80041f3408 @attributes={"value"=>"Cíao"}, @prefix_options={:resource=>"products", :resource_id=>149523945}, @persisted=true>,
#<ShopifyAPI::Metafield:0x007f80041f3160 @attributes={"value"=>"1"}, @prefix_options={:resource=>"products", :resource_id=>149523945}, @persisted=true>
]