I use `select_all(:teachers)` instead of your `select(*'*teachers.**'*)` in such case. Sequel then casts the object to the proper `Teacher` model class, which is what you want I suppose. I don't know if it's the best way.
I must admit I didn't find the documentation on this matter, and just realized it works this way (it gets especially messy when the column names collide, for example `:id` column). At least I didn't make general sense of the behaviour. Jeremy, maybe there is a resource where the details could be learned for newcomers? Or I missed the place in the doc. I'd be happy to make a doc PR once I get the grip on the thing. Best, Michael Le jeu. 7 janv. 2021 à 09:17, Mateusz Urbanski < [email protected]> a écrit : > I have the following query: > > [4] pry(main)> *Teacher*.join_table(:inner, :categories_teachers, > teacher_id: :id, category_id: *Category*.last.id).all > > I, [2021-01-07T09:14:16.170823 #9418] INFO -- : (0.000264s) SELECT * FROM > "categories" ORDER BY "id" DESC LIMIT 1 > > I, [2021-01-07T09:14:16.171589 #9418] INFO -- : (0.000261s) SELECT * FROM > "teachers" INNER JOIN "categories_teachers" ON > (("categories_teachers"."teacher_id" = "teachers"."id") AND > ("categories_teachers"."category_id" = > 'fcd35ff1-e9bd-4e29-a7a3-3a43e2cb20e4')) > > > This query returns for me additional columns that not belongs to teachers > table. > > > I tried to fix this with using select method but it doesn't work: > > > *Teacher*.join_table(:inner, :categories_teachers, teacher_id: :id, > category_id: *Category*.last.id).select(*'*teachers.**'*).all > > > How can I fix that? > > -- > You received this message because you are subscribed to the Google Groups > "sequel-talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sequel-talk/09e4966a-1864-4561-93e0-74311e1f3582n%40googlegroups.com > <https://groups.google.com/d/msgid/sequel-talk/09e4966a-1864-4561-93e0-74311e1f3582n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CAAkfp_RTwGDDgJCo8%3DynGFX6PW3Ai1m%2Bkqap6tMRGzkJ4SQFDA%40mail.gmail.com.
