rafaelfranca on master
Prevent TextHelper#word_wrap fr… Merge pull request #34488 from … (compare)
rafaelfranca on master
Indent guides as rails help com… Homogenize rails help output I… Merge pull request #34085 from … (compare)
rafaelfranca on 5-2-stable
Merge pull request #34106 from … (compare)
Okay, I'll try these commands again. See what happens. rails generate scaffold Customer name:string phone:integer
rails generate scaffold Cases topic:string created_at:datetime
Problem is, sometimes the error messages their meanings aren't as clear to me as they are to you.
Stephen D
in the index method
Stephen D
case
is
Johan Smits
Or a the Class Stripe
Sure. I'm working with Textacular, which is a wrapper around pg_search. I'm using a form of multisearch using a database view, that looks at fields in two models: Case (case_number and short_title field) and CaseEvent (short_title and party_name). My database view joins the four fields into a view called Searches. Using textacular, I can do something like:
Search.web_search('richard')
=> #<ActiveRecord::Relation [#<Search searchable_id: 441, searchable_type: "Case", term: "R. v RODRIGUEZ, RICHARD">, #<Search searchable_id: 440, searchable_type: "Case", term: "R. v RODRIGUEZ, RICHARD">, #<Search searchable_id: 551, searchable_type: "Case", term: "OWIREDU, RICHARD">, #<Search searchable_id: 388, searchable_type: "Case", term: "R. v DESOUSA, RICHARD">, #<Search searchable_id: 387, searchable_type: "Case", term: "DESOUSA, RICHARD">, #<Search searchable_id: 923, searchable_type: "Case", term: "R. v KLEPACKI, RICHARD">, #<Search searchable_id: 620, searchable_type: "Case", term: "RICHARD v TREMBLAY">, #<Search searchable_id: 439, searchable_type: "Case", term: "R. v RODRIGUEZ, RICHARD">, #<Search searchable_id: 440, searchable_type: "Case", term: "RODRIGUEZ, RICHARD">, #<Search searchable_id: 802, searchable_type: "Case", term: "RICHARD, MATHIEU">, ...]>
But I want to go from that relation to a set of Cases, but still in relation form, as I'm later filtering and possibly sorting it. I can get the cases by doing:
Search.web_search('richard').preload(:searchable).to_a.map!(&:searchable)
=> [#<Case id: 621, case_number: "FC-13-00000891-0003", short_title: "ROWLAND v SPINDLER", case_type_id: 4, court_id: 1, created_at: "2020-06-02 20:45:47", updated_at: "2020-06-02 20:45:47">, #<Case id: 441, case_number: "471199820424100", short_title: "R. v RODRIGUEZ, RICHARD", case_type_id: 2, court_id: 1, created_at: "2020-06-02 20:45:37", updated_at: "2020-06-02 20:45:37">, #<Case id: 440, case_number: "47119982021900", short_title: "R. v RODRIGUEZ, RICHARD", case_type_id: 2, court_id: 1, created_at: "2020-06-02 20:45:37", updated_at: "2020-06-02 20:45:37">, #<Case id: 551, case_number: "FC-19-00000134-0000", short_title: "DE SOUSA v OWIREDU", case_type_id: 4, court_id: 1, created_at: "2020-06-02 20:45:46", updated_at: "2020-06-02 20:45:46">, #<Case id: 388, case_number: "47119982034700", short_title: "R. v DESOUSA, RICHARD", case_type_id: 2, court_id: 1, created_at: "2020-06-02 20:45:36", updated_at: "2020-06-02 20:45:36">, #<Case id: 387, case_number: "471199819808400", short_title: "R. v DESOUSA, RICHARD", case_type_id: 2, court_id: 1, created_at: "2020-06-02 20:45:36", updated_at: "2020-06-02 20:45:36">, #<Case id: 923, case_number: "211199820S208600", short_title: "R. v KLEPACKI, RICHARD", case_type_id: 2, court_id: 1, created_at: "2020-06-02 20:46:17", updated_at: "2020-06-02 20:46:17">, etc…
But then it's an array, not a relation, which slows things down significantly (the :searchable attribute comes from Textacular itself). Is there any way to get from a Relation of Search objects to a relation of Case objects while keeping it in ActiveRecord form for possible database operations later in the same method?
irb(main):122:0> Search.web_search('heather').includes(:searchable).joins(:searchable)
Traceback (most recent call last):
ActiveRecord::EagerLoadPolymorphicError (Cannot eagerly load the polymorphic association :searchable)