foxnewsnetwork / autox

yet another personal ember addon
MIT License
0 stars 0 forks source link

introduce proper query scopes into autox elixir side #17

Open foxnewsnetwork opened 8 years ago

foxnewsnetwork commented 8 years ago

right now, we do something like

thread
|> build_assoc( :posts )
|> QueryUtils.run

Which delegate directly to Ecto's belongs_to and has_many associations. This isn't good because it doesn't allow proper scoping of the association, and we're kind of at a loss if we wanted to do something like:

has_many :deleted_posts, Post, &is_deleted/1 # can't do this

This just means we need another layer between the controller and the Ecto Models where we will declare scopes, probably something like:

defscope deleted_posts( thread) do
  thread
  |> build_assoc(:posts)
  |> where([x], x.deleted_at is not null)
end

And have the autox toolchain be smart about looking for scopes.