0

given:

modelOne
    belongs_to :modelTwo
    field_one

modelTwo
    has_many :modelOnes
    field_two

how would I select both field_one and field_two using an includes

all of the answers I've found so far go along the lines of

modelTwo.includes(:modelOne).select(<:field_one, :field_two or 'model_twos.field_two, model_ones.field_one'>).references(:modelOne)

but all of them either give me an undefinedTable error on the included tables field or the results dont include the field on the included table

Jarfis
  • 125
  • 11
  • Did you visit this [answer](http://stackoverflow.com/questions/22312901/activerecord-join-query-and-select-in-rails)? – Vaibhav Dhoke Aug 10 '16 at 16:51
  • I sure did, it's not what i was looking for, I need the response from the query to be along the lines of [field_one, field_two],[field_one, field_two], etc – Jarfis Aug 10 '16 at 17:00
  • Do you have an instance of modelTwo already in memory, and you are looking for a method to invoke that will produce the array output you reference? Or are you looking for a query that will accept (e.g.) a modelTwo ID and produce this output? – Jim Van Fleet Aug 10 '16 at 18:18
  • So, normally with the select it'd give: `, #, etc, etc]>` or thereabouts. I would like to get a result like: `, #, etc, etc]>` or something similar. `select` looked perfect at first, but apparently it can't do what I need. – Jarfis Aug 10 '16 at 18:50

0 Answers0