pluck_to_hash | Extend ActiveRecord pluck to return array | Object-Relational Mapping library
kandi X-RAY | pluck_to_hash Summary
kandi X-RAY | pluck_to_hash Summary
Extends ActiveRecord by adding pluck_to_hash method that returns array of hashes instead of array of arrays. Useful when plucking multiple columns for rendering json or you need to access individual fields in your view for example. Supports pluck_to_struct since version 0.3.0. pluck_to_struct returns an array of structs.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of pluck_to_hash
pluck_to_hash Key Features
pluck_to_hash Examples and Code Snippets
Community Discussions
Trending Discussions on pluck_to_hash
QUESTION
I'm trying to deploy my Rails 5.0 on heroku after a bundle update. I'm blocked by an issue on assets:precompile
...ANSWER
Answered 2020-Jun-30 at 09:08Thanks to @Les Nightingill, I found the issue.
It was not directly linked to assets generation, but the probleme was indicated at the first error line in the logs :
QUESTION
I have this data model
House has_many :floors
(attributes => name, size, city)
Floor has_many :rooms, belongs_to :house
(attributes => name, rooms_count)
Room has_many :furnitures, belongs_to :floor
(attributes => name, size)
Furniture belongs_to :room
(attributes => name, size, color)
and I want to query that way
House.where(city: 'Paris').joins(floors: {rooms: :furnitures}).pluck(name, floors.id, floors.name, rooms.name, furnitures.name)
This is the SQL request I want to have :
=> SELECT houses.name, floors.id, floors.name, rooms.id, rooms.name, furnitures.id, furnitures.name FROM "houses" INNER JOIN "floors" ON "floors"."company_id" = "houses"."id" INNER JOIN "rooms" ON "rooms"."building_id" = "floors"."id" INNER JOIN "furnitures" ON "furnitures"."floor_id" = "rooms"."id" WHERE "houses"."name" = $1 [["city", "Paris"]]
Now I get the results raw in a big array of arrays, and I want to sort it like this, but I'm quite stuck :
[
{
name: 'toto',
floors: [
{
id: '123',
name: 'tata'
rooms: [
{
name: 'titi',
furnitures: [
{
name: 'table'
},
{
name: 'chair'
}
]
}
]
}
]
}
]
I need to avoid N+1 request and only refuse to have a select *.
The pluck_to_hash
gem could be helpful but does not work very well with multi tables queries.
Thanks for you help.
ANSWER
Answered 2018-May-01 at 09:53Why not use deep_pluck to pluck nested associations.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pluck_to_hash
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page