Skip to content
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

Can't swap Primary Position with Flex without an open Flex Position #521

Open
axelclark opened this issue Jan 26, 2019 · 6 comments
Open

Comments

@axelclark
Copy link
Owner

Can't swap Primary Position with Flex without an open Flex Position

For example, can't swap Kentucky from CBB to Flex1 and North Carolina from Flex1 to CBB

@axelclark
Copy link
Owner Author

axelclark commented May 4, 2019

Possible fixes:

  1. Allow owner to move player into "Unassigned" position
    -- Unassigned == 0 points to motivate owners to move to a position
  2. Identify a "swap" transaction and have the software break the transaction into 2 moves
    -- Primary to "Unassigned"
    -- From Flex1 to CBB & from "unassigned to Flex1

@axelclark
Copy link
Owner Author

axelclark commented May 4, 2019

Maybe need to modify cast_assoc(:roster_positions)

def owner_changeset(struct, params \\ %{}) do
struct
|> cast(params, [:team_name, :autodraft_setting])
|> validate_required([:team_name])
|> cast_assoc(:roster_positions)
|> cast_assoc(:draft_queues)
|> validate_length(:team_name, max: 16)
end

Maybe add a test here

describe "update_team/2" do
test "updates a fantasy team and its roster positions" do
league = insert(:fantasy_league)
team = insert(:fantasy_team, team_name: "Brown", fantasy_league: league)
position = insert(:roster_position, fantasy_team: team)
team = Store.find_for_edit(team.id)
attrs = %{
"team_name" => "Cubs",
"roster_positions" => %{"0" => %{"id" => position.id, "position" => "Flex1"}}
}
{:ok, team} = Store.update_team(team, attrs)
assert team.team_name == "Cubs"
assert Enum.map(team.roster_positions, & &1.position) == ~w(Flex1)
end
end

@axelclark
Copy link
Owner Author

System should do this automatically...

@axelclark
Copy link
Owner Author

axelclark commented Aug 4, 2019

https://www.postgresql.org/docs/current/sql-createtable.html

DEFERRABLE
NOT DEFERRABLE
This controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command. Checking of constraints that are deferrable can be postponed until the end of the transaction (using the SET CONSTRAINTS command). NOT DEFERRABLE is the default. Currently, only UNIQUE, PRIMARY KEY, EXCLUDE, and REFERENCES (foreign key) constraints accept this clause. NOT NULL and CHECK constraints are not deferrable. Note that deferrable constraints cannot be used as conflict arbitrators in an INSERT statement that includes an ON CONFLICT DO UPDATE clause.

INITIALLY IMMEDIATE
INITIALLY DEFERRED
If a constraint is deferrable, this clause specifies the default time to check the constraint. If the constraint is INITIALLY IMMEDIATE, it is checked after each statement. This is the default. If the constraint is INITIALLY DEFERRED, it is checked only at the end of the transaction. The constraint check time can be altered with the SET CONSTRAINTS command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant