How to write Ecto queries without PostgreSQL views?

Hi! I’m super new to ecto and struggling with writing queries without using the postgreSQL views that I learned in college.

So what I’m wondering is:

Given the following schemas:

schema "s1" do
field :f1, :dtype1
field :f2, :dtype2

belongs_to :b1, B1
belongs_to :b2, B2
belongs_to :b3, B3
end
schema "s2" do
field :f3, :dtype2

belongs_to :b1, B1
belongs_to :b2, B2
belongs_to :b3, B3
belongs_to :b4, B4
end

how do I join s1 with s2 on b1, b2, and b3 without doing a million joins and associations?

In the end I actually want to update every instance of s1.f2 to be equal to the corresponding s2.b4.

THANKS!!!

Hi and welcome.

There is no rule saying you cannot use views in ecto, you just replace your schema name with the name of the view.

2 Likes