-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
analytics page #416
analytics page #416
Conversation
lib/dash/hub_stat.ex
Outdated
@@ -6,7 +6,7 @@ defmodule Dash.HubStat do | |||
schema "hub_stats" do | |||
field :measured_at, :utc_datetime | |||
field :storage_mb, :integer | |||
field :hub_id, :integer | |||
belongs_to :hub, Hub, foreign_key: :hub_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have this weird error "warning: invalid association hub
in schema Dash.HubStat: associated schema Dash.Hub does not have field id
" which I know.. it has "hub_id" but am I not doing that right here? saying ":hub_id"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don’t actually need to set the :foreign key
option, since it defaults to the name of the association suffixed by _id
. The option you want is :references
, which sets the key on the other schema to be used for the association. That’s the one that defaults to :id
.
belongs_to :hub, Hub, foreign_key: :hub_id | |
belongs_to :hub, Hub, references: :hub_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bryanenders your fix worked but isn't the primary key on hubs :hub_id?
@primary_key {:hub_id, :id, autogenerate: true}
was thinking that overrides the :id?
thanks again for helping!
lib/dash.ex
Outdated
from(hub in Hub, | ||
join: stat in assoc(hub, :hub_stats), | ||
where: stat.measured_at >= ^start_date and stat.measured_at <= ^end_date, | ||
select: hub |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The :select
may not be necessary
import Dash.Utils, only: [rand_string: 1] | ||
import Ecto.Changeset | ||
import Ecto.Query | ||
require Logger | ||
|
||
@type id :: pos_integer | ||
@type t :: %__MODULE__{account_id: id} | ||
|
||
@derive {Jason.Encoder, only: [:tier, :hub_id]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this Elixir project isn’t long for this world, this is fine. If we expected it to live on, I’d instead suggest picking off the fields we want where they’re used: the controller/view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be a great part to pair on if you feel like passing on some wisdom. I was trying it put that in the controller / view and just couldn't figure It this seems super heavy handed, and like you said is ok since we are out but I'd love to see how to do it properly if you have time.
There are some things I’d recommend if this Elixir project were living on. Since it’s not, this looks like it should do the trick with that |
Creating a route that can get data from the hubstat join hubs table to see all the active hubs in a given time period.