2016-09-04 9 views
1

を動作しません、私はこれは私のClojureの宣言があり、多くの

(declare user_account recipe) 

(kc/defentity user_account 
      (kc/entity-fields :email :password) 
      (kc/has-many recipe {:fk :user_account_id}) 
      ) 

(kc/defentity recipe 
       (kc/entity-fields :user_account_id :name :description) 
       (kc/belongs-to user_account {:fk :user_account_id}) 
      ) 

で、私はuser_accountテーブルを選択することはできません2つのテーブル

CREATE TABLE public.user_account 
(
    id integer NOT NULL DEFAULT nextval('user_account_id_seq'::regclass), 
    email character(50) NOT NULL, 
    password character(100) NOT NULL, 
    CONSTRAINT user_account_pkey PRIMARY KEY (id) 
) 

CREATE TABLE public.recipe 
(
    id integer NOT NULL DEFAULT nextval('recipe_id_seq'::regclass), 
    user_account_id integer NOT NULL, 
    name text NOT NULL, 
    description text NOT NULL, 
    CONSTRAINT recipe_pkey PRIMARY KEY (id), 
    CONSTRAINT recipe_user_account_id_fkey FOREIGN KEY (user_account_id) 
     REFERENCES public.user_account (id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE NO ACTION 
) 

を持ってrecipe

user=> (sql-only (kc/select user_account (with recipe) (where {:id 1}))) 
"SELECT \"user_account\".\"email\", \"user_account\".\"password\" FROM \"user_account\" WHERE (\"user_account\".\"id\" = ?)" 

答えて

1

私は同じ問題に遭遇しました。解決策は、親エンティティのentity-fieldsリストにpkフィールドを追加することでした。それは本当に直感的ではなく、問題は貧弱な文書にあるようです。したがって、解決策は次のようになります。

(declare user_account recipe) 

(kc/defentity user_account 
      (kc/entity-fields :id :email :password) 
;       ^^^ fix is here 
      (kc/has-many recipe {:fk :user_account_id}) 
      ) 

(kc/defentity recipe 
       (kc/entity-fields :user_account_id :name :description) 
       (kc/belongs-to user_account {:fk :user_account_id}) 
      ) 
+1

この問題が原因でyesqlに切り替えられ、ドキュメントも不十分です。しかし、答えをありがとう – nam

関連する問題