微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在与字段相同的行上声明外键?

如何解决在与字段相同的行上声明外键?

这有效,但很冗长:

override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?): View? {
    val view = inflater.inflate(R.layout.file_explorer,container,false)

    class MyViewHolder(val item: View): RecyclerView.ViewHolder(item) {
        init {
            item.setonClickListener {
                Log.d("path",files[adapterPosition].path)
                Log.d("pos",adapterPosition.toString())
                goto(files[adapterPosition].path)
            }
        }
    }

    val recyclerView = view.findViewById<RecyclerView>(R.id.files)
    recyclerView.addItemdecoration(DividerItemdecoration(recyclerView.context,DividerItemdecoration.VERTICAL))
    recyclerView.adapter = object: RecyclerView.Adapter<MyViewHolder>() {
        override fun onCreateViewHolder(parent: ViewGroup,viewType: Int): MyViewHolder {
            val item = LayoutInflater.from(parent.context).inflate(R.layout.item,parent,false)
            return MyViewHolder(item)
        }

        override fun onBindViewHolder(holder: MyViewHolder,position: Int) {
            holder.item.findViewById<TextView>(R.id.text).text = files[position].name
        }

        override fun getItemCount() = files.size
    }

    return view
}

这次尝试:

CREATE TABLE located (
    id SERIAL NOT NULL PRIMARY KEY,container_id BIGINT NOT NULL,CONSTRAINT fk_l2c FOREIGN KEY (container_id) REFERENCES containers
);

失败:

CREATE TABLE located (
    id SERIAL NOT NULL PRIMARY KEY,container_id BIGINT NOT NULL FOREIGN KEY REFERENCES containers
);

有没有办法在与 container_id 相同的行上声明外键?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。