Questions tagged [pluck]

pluck is a Rails function used to query a single or multiple columns from the underlying table of a model.

pluck is a Rails function used to query a single or multiple columns from the underlying table of a model. It accepts a list of column names as argument and returns an array of values of the specified columns with the corresponding data type.

69 questions
0
votes
1 answer

Pluck doesn't return a bother records they have the same name

I have a pluck that is turned into a hash and stored in a variable @keys_values_hash = Hash[CategoryItemValue.where(category_item_id: @category_item.id).pluck(:key, :value)] If 2 records have the same :key name then only the most recent record is…
Rob
  • 1,835
  • 2
  • 25
  • 53
0
votes
2 answers

What is simplest way to convert :pluck or :collect results to array of strings in Rails?

I have a model called Record and belongs Product model, the price column type is hexadecimal. Rails already convert it to string in view. But I wanna get them in my console queries. Example code for pluck: Product.first.records.pluck(:price) This…
thatway_3
  • 404
  • 1
  • 10
  • 22
0
votes
1 answer

Filtering array with reject + conditions in rails

I'm trying to filter an array of matched records with multiple conditions and can't seem to figure it out, I've tried a lot of different things and googled everything but nothing... here's the code: if @post.last_post? @recommendations =…
LessPixels
  • 145
  • 7
0
votes
1 answer

pluck scope nil value in Ruby on rails

Hi can someone tell me what went wrong here? @organizations_of_user = user.memberships.verified.pluck :organization_id @organizations_of_user << nil @permitted_category_ids= Category.where(......, organization_id:@organizations_of_user) seems like…
MangooSaSa
  • 3,411
  • 3
  • 14
  • 16
0
votes
1 answer

ActiveRecord using pluck with includes/left outer joins

When I do includes it left joins the table I want to filter on, but when I add pluck that join disappears. Is there any way to mix pluck and left join without manually typing the sql for 'left join' Here's my case: Select u.id From users u Left…
user433342
  • 859
  • 1
  • 7
  • 26
-1
votes
1 answer

i want to add 10% extra of main price of service that get by api on my laravel web application

i have a laravel web application and when i try to update price form provider it update same price that already have provider i want to add extra 10% profit with provider price anyone here who can help me here is code public function…
Juwel1211
  • 5
  • 3
-1
votes
3 answers

How can i show in a SELECT two columns of a table using PLUCK

I'm trying to use the PLUCK method to display two columns of a table when selecting them $driverItems = Driver::pluck('driverName','id')->toArray(); I need to display the driver name and the Licence
-1
votes
4 answers

Using Plucked Values in Ruby on Rails

Given a model named Album, I want to use the values I pluck. For starters, I want to try to print the values. How can I do this? Here is my current code: my_arr = Album.where(title: "Greatest Hits", artist: "The Beatles").pluck(:publisher,…
Rob
  • 11
  • 4
-2
votes
1 answer

Laravel Pluck Concat Relations

Im using laravel 8 to my project, trying to pluck data from a Model $user = Users::with('media')->get()->pluck('media.title', 'id')->all(); I got the Output { "sample": 1, } My expected output,Looking for the value combine a…
Agent47
  • 69
  • 3
  • 13
1 2 3 4
5