問題タブ [ecto]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
elixir - Ecto における多対多の関係
ユーザー モデルとチャット モデルがあります。直感的に、いつでも複数の人が同じチャット グループに所属し、各人が多くのチャット グループを持つことができます。したがって、チャット グループは複数の に属している必要がありuser_id
ます。
チャット グループとユーザーの私のスキーマは次のとおりです。
これを処理する方法について何か提案はありますか?
elixir - Ecto モデル `undefined function: ` マクロ ***in iex*** で作業する場合
Ecto プロジェクトでこの問題が発生しています。どのクエリも機能していません。私はグーグルとgithubの問題を少し検索しました。いくつかありますが、私の問題とは関係ありません。
この質問は、この質問から開始されましたhttps://github.com/elixir-lang/ecto/issues/602#issuecomment-145596702 (主に私の問題に関連しています)
で爆破** (RuntimeError) undefined function: u/0
。そのモデルだけでなく、他のモデルも同様です。私の担当者。
現在、db からの読み取りはすべて 経由で行われてpsql
います。それは仕事をしますが、面倒です。:)
参考までに。
そして移住
mysql - Phoenix-Framework : transform, associate and nil check Ecto parent model when creating child model
I'm coming to the Phoenix framework from Rails. So far it's been a fairly easy transition. Phoenix is newer, though, and I'm having trouble finding some specific information:
I'm using my Phoenix app as an API service layer.
I want my UI form (and incoming curl requests) to use a virtual field
to find an associated parent model, and fill the child model's changeset
with the appropriate attribute. So far, so good:
in my child model:
...
This is where I'm stuck. I do not want to allow the child to be created without a parent. How and where do I nil
check the parent model? Everything I've tried has either blocked or allowed creation unconditionally, despite conditional statements.
It seems like I need to preload the parent model before the check, since Phoenix is designed to prevent people like me from abusing lazy load. Unfortunately, I don't know what the proper load pattern is in general, so I'm not sure how to apply it here. (I'm using MySQL, if that's relevant)
Hints and tips about where to look and what to look at to help me figure this out are appreciated! Thanks!
---EDIT---
Per @Gazler 's advice I have made sure that my child model migration has a reference:
I'm still a little lost -- I want to find the parent
by the parent field parent_name
("Jane Doe"
), make sure the parent model exists, and associate the child using parent_id
(1
). I'm not sure how to trigger these actions around using a virtual field.
So, I'm not sure how to structure finding the parent, building the association, and checking the foreign key validation, since the foreign key will never exist in the original params. Thoughts?
Thanks so much.
---RESOLVED---
Using @Gazler 's updated answer, I can successfully nil check my parent model in the child controller without a virtual attribute or before_insert.
this validates the incoming parameters exactly like i need! thanks @Gazler!
postgresql - Postgresを使ってEctoで配列を保存する方法
Postgres を使用して Ecto で浮動小数点値の配列を格納したいと考えています。Phoenix Framework と Elixir で Ecto を使用しています。
このためのモデルと移行をどのように定義しますか?
ウェブを検索する以外は、あまり試していませんが、役に立つものは何も見つかりませんでした:-(
私は次のようなスキーマでモデルを定義しようとしました:
「フィールド:my_arrayの無効または不明なタイプ:配列」というエラーが発生しました
elixir - 更新時のEcto.Changeset関連のモデルエラー
has_one アソシエーションの更新で Ecto がエラーを出しています:
問題のモデル:
コントローラー更新アクション
パラメータ
parent = %{"some_number" => "902", "thing" => %{"somethingfield" => "blah", "parent_id" => "8"}
エラー
ドキュメントに基づいて、親モデルのチェンジセット関数が親から孤立した「モノ」を見ているように見えますが、理由がわかりませんか?
新規/作成アクションは問題なく機能します。