Avoid problems with duplicate column names and joins #2272
Closed
davetron5000
started this conversation in
General
Replies: 4 comments
-
Assuming you have the appropriate |
Beta Was this translation helpful? Give feedback.
0 replies
-
That didn't work - it still uses Here are my models: # Including this in case the extra class matters
AppDataModel = Class.new(Sequel::Model)
class AppDataModel
end
class Plan < AppDataModel
many_to_one :meal
end
class Meal < AppDataModel
one_to_one :plan
end |
Beta Was this translation helpful? Give feedback.
0 replies
-
I might opt for the |
Beta Was this translation helpful? Give feedback.
0 replies
-
That plugin worked, thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Suppose I have
plans
that contains ameal_id
that is a foreign key intomeals
. Suppose further that both tables have a fieldexternal_id
.Suppose this data:
This code results in a
Plan
object whoseexternal_id
value ismeal_id
, notplan_1
:The reason is that the code above generates this SQL:
Postgres does not prefix the columns with the table name, so the output dataset has two columns named
external_id
.Not that I expect Sequel to act like Active Record, but it's hard to see how this behavior would ever be desired and could be extremely confusing.
I can address this like so:
So my question is - is there another way to avoid the behavior without using
select_all
- I would love if the default behavior using joins would be to qualify the values with the table name so that the ORM would work as expected (or at least as I expect :)Is there some setting or way to do this? If not, is there an obvious extension point where I could make an extension or plugin that provided this behavior?
Beta Was this translation helpful? Give feedback.
All reactions