2016-09-04 4 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