schema "postings" do
belongs_to :account, Account
timestamps()
end
def create_changeset(posting, attrs) do
posting
|> cast(attrs, [])
|> validate_required([])
|>foreign_key_constraint(:account_id)
end
def create_posting(attrs) do
change(%Posting{}, %{account_id: attrs["account_id"]})
|> Posting.create_changeset(attrs)
|> Repo.insert()
end
schema "accounts" do
has_many :postings, Posting
timestamps()
end
attrs = %{"account_id"=>1}
using
Repo.insert! %Posting{
account_id: 1
}
however works.






















