schema "users" do
field :email, :string
field :username, :string
field :password_hash, :string
field :password, :string, virtual: true
belongs_to :role, Catastore.Role
belongs_to :store, Catastore.Store
timestamps()
end
and a store model
schema "stores" do
field :name, :string
has_many :users, Catastore.User
timestamps()
end
i want to when i create a new store update the the user database. but i can’t find a way to do it with Ecto, it is not the best pratice to put the ID manually?
As for best practice, it’s really what suits you. Before Ecto 2, Schemas (nee Models) were everything, but as Ecto 2 has progressed schemaless queries have become better supported and more common. They really do free you up from having to turn data you already have (e.g. an id) into a struct Just Because™ the API dictates it. But … if you already have that data in a Schema struct, then go ahead and use it! The nimbleness of Ecto is quite wonderful at times.