首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >has-many不起作用

has-many不起作用
EN

Stack Overflow用户
提问于 2016-09-05 03:25:09
回答 1查看 107关注 0票数 1

我有两张桌子

代码语言:javascript
复制
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
)

这是我的clojure声明

代码语言:javascript
复制
(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})
              )

而且我不能用recipe选择user_account

代码语言:javascript
复制
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\" = ?)"
EN

回答 1

Stack Overflow用户

发布于 2016-10-10 20:59:35

我遇到了同样的问题。解决方案是将pk字段添加到父实体的entity-fields列表中。这真的不直观,似乎问题出在一个糟糕的文档中。因此,解决方案应该是:

代码语言:javascript
复制
(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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39320669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档