I want to only return certain fields in query.
我想只返回查询中的某些字段。
For example:
例如:
ShopifyAPI::Metafield.find(:all,:params=>{:resource => "products"},:fields=>['value'])
I only want to return the value field from the metafield object
我只想从metafield对象返回值字段
1 个解决方案
#1
0
You came close. You forgot to actually provide an ID for a resource. In your case, since you're looking for all the values of the metafields assigned to a product, you need to provide the product ID.
你走近了。您忘记实际提供资源的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>
]
#1
0
You came close. You forgot to actually provide an ID for a resource. In your case, since you're looking for all the values of the metafields assigned to a product, you need to provide the product ID.
你走近了。您忘记实际提供资源的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>
]