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
2
votes
2 answers

Laravel collection: return only relationship and key

I have a collection that resembles this: $a = Model::with(['sub' => function($q) { $q->select('id', 'name') }])->get(); This returns the following collection: { 0: { id: 0001, name: "item 1", type: "type a" …
Typhoon101
  • 2,063
  • 8
  • 32
  • 49
2
votes
0 answers

CKeditor integration throwing Uncaught RangeError: Maximum call stack size exceeded. on focus of text area

I am working on pluck integration with our ecommerce site - Pluck integration forums include a ckeditor where a user can type and post in to a forum. But with our integration, upon clicking the ck editor text area i am getting the following…
1
vote
2 answers

How to sort alphabetically with a form select using pluck.all

I have a form and there's a drop down to choose dance styles however, this list is not in alphabetical order. My form for the select is: <%= f.label "Dance Style", class: "form-label" %> <%= f.select :dance_styles_id_in, DanceStyle.all.pluck(:name,…
Ogarocious
  • 119
  • 6
1
vote
0 answers

Pluck give string instead of integer

I use laravel 9.25.1 and php 8.1.8. I have script $this->productId = $guest->products()->pluck('product_id')->toArray(); This script give me integer in localhost but it gives me string in hosting. I browsed everywhere to find the root cause and…
Jonathan
  • 11
  • 4
1
vote
1 answer

Laravel pluck, groupBy custom date Format

Can't Format created_at when use pluck. VisitorsStatistic::where('landing_page_id', $this->landing_page->id) ->select('created_at', DB::raw('count(*) as visitors')) ->whereMonth('created_at', '>=', $this->start_month) …
Aciddiz
  • 495
  • 5
  • 14
1
vote
1 answer

Laravel Pluck Selected option

i wants to show selected category option in Sub-category edit form. Am using pluck function for fetch category from database. {{ Form::model($subcategories,['route'=> ['subcategories.edit',$subcategories->id],'method'=>'post']) }}
Ripon Uddin
  • 709
  • 3
  • 14
  • 29
1
vote
1 answer

Eloquent: Retrieve pluck collection with trashed entries

I want to get all Address IDs, including the trashed ones, with pluck. This is how it is working but I don't get the trashed ones as well...: $clientIDs = Client::pluck('address_id')->all(); This is what I tried already: $clientIDs =…
Jan
  • 1,180
  • 3
  • 23
  • 60
1
vote
0 answers

Laravel 5.4 join concat pluck

I am writing an assignment system for biodata record. The data tables: preceptorids preceptorids_id | bio_id | preceptors_status ----------------| --------------------------- 1 | 5 | 3 bios bio_id | bio_thana | boi_chaya…
Dipendra Deshar
  • 65
  • 2
  • 12
1
vote
3 answers

How to get all the values of single column using laravel 4.2

I am using pluck method to get data from single column $systems = OptionUser::pluck('user_skill'); This systems variable returning only one value while I have around 50 values in this table. Please suggest what is correct way to get all the data…
Ramkishan Suthar
  • 403
  • 1
  • 7
  • 26
1
vote
1 answer

Laravel 5.3 select pluck method

Controller method: public function edit($id){ $match2 = Match::pluck('team_a_id', 'id'); return view('admin.accept.edit', compact('match2')); } And view file: {{ Form::select('matches_id', $match2, null, ['class' => 'form-control'])…
michal
  • 1,534
  • 5
  • 28
  • 62
1
vote
1 answer

Using Wikipedia-Client Gem to Update Rails Database

My ruby and Rails is a bit rusty. I have a table in my database called institutes which has some of the columns filled. I want to use the Wikipedia-Client gem to fill some of the others. I want to use the name attribute to find the page on Wikipedia…
Dave C
  • 367
  • 5
  • 19
1
vote
2 answers

rails, form select, pluck 2 fields

I'm trying to simply display 2 fields (first name and last name) in a form select (f.select). Here is my code: <%= f.select :person, User.where(verified_person: 't').pluck(:first_name, :last_name) %> With the code above, the select drop-down field…
gitastic
  • 516
  • 7
  • 26
1
vote
1 answer

How to get an object from an array Ruby on Rails

In controller I use pluck method to get id and name from my database @user1 = User.where(name: 'Alex').pluck(:id, :name).first @user2 = User.where(name: 'Alex').pluck(:id, :name) It return array @user1 = `[3, 'Alex']` @user2 = [[3,'Alex'],[4,…
user3563581
  • 67
  • 1
  • 7
1
vote
2 answers

Neo4j gem - Plucking multiple nodes/relationships

This may not be possible as it is right now but I have a query like so events = Event.as(:e).where("(( e.date_start - {current_time} )/{one_day_p}) < 1 ").users(:u, :rel).where("rel.reminded = {reminded_p}" ).params(reminded_p: false, one_day_p:…
Clam
  • 935
  • 1
  • 12
  • 24
1
vote
4 answers

Retrieving multiple Records,columns using Joins and pluck

I found a weird behaviour from Active Record Pluck. My query is Friend.joins('INNER JOIN users ON friends.friend_id = users.id').where("user_id=? AND (status=? or status=?)", 4,"true","").pluck("users.first_name, users.last_name") It is to join…
santosh
  • 1,611
  • 1
  • 13
  • 21