小编buz*_*sin的帖子

Prisma Schema 中的多态性 - 最佳实践?

这更像是一个设计问题,而不是一个编码问题。假设有以下架构:

// schema.prisma
// Solution 1

model Entity {
  id    Int          @id @default(autoincrement())
  attrs EntityAttr[] 
}

model EntityAttr {
  id       Int         @id @default(autoincrement())
  value    Json        // or String, doesnt matter much here
                       // the point is I need to attach info on the
                       // join table of this relation
  attr     Attr        @relation(fields: [attrId], references: [id])
  entity   Entity      @relation(fields: [entityId], references: [id])

  entityId Int
  attrId   Int

  @@unique([entityId, attrId])
}

model Attr {
  id       Int          @id @default(autoincrement())
  entities EntityAttr[]   
}
Run Code Online (Sandbox Code Playgroud)
// Solution …
Run Code Online (Sandbox Code Playgroud)

nexus graphql prisma prisma-graphql nexus-prisma

5
推荐指数
1
解决办法
7303
查看次数

钻石问题初始化 - 默认构造函数被忽略?

可能重复的:

考虑以下示例:

#include <iostream>
#include <cassert>

struct MyEnum {
    enum valid { CASE1, CASE2, DEFAULT };
    valid value;
    MyEnum(valid value = DEFAULT) : value(value) {}
};

class Base {
protected:
    MyEnum value;

public:
    Base() = default;
    Base(MyEnum value) : value(value) {
        std::cout << "Base::Base(MyEnum).\n";
    }  
};

class ReadableBase : public virtual Base {
public:
    ReadableBase() = default;
    ReadableBase(MyEnum value) : Base(value) {
        std::cout << "ReadableBase::ReadableBase(MyEnum).\n";
    }

public:
    MyEnum read() { return value; }
};

class WriteableBase : public …
Run Code Online (Sandbox Code Playgroud)

c++ diamond-problem c++17

1
推荐指数
1
解决办法
106
查看次数

如何为专用模板类提供更紧凑的定义?

考虑以下场景:

template <
    typename T,
    bool B = std::is_default_constructible_v<T>>
class toy_example;

template<typename T>
class toy_example<T, true>
{
public:
    toy_example() = default; // e.g. for default constructible types
    toy_example(const T& value);

public:
    void monomorphic(T);

private:
    T m_value;
};

template<typename T>
class toy_example<T, false> 
{
public:
    toy_example() = delete; // e.g. for non-default constructible types
    toy_example(const T& value); // Repeated declaration

public:
    void monomorphic(T); // Repeated declaration

private:
    T m_value;
};

// Implementation
template<typename T>
toy_example<T, true>::toy_example(const T& value) : m_value(value) {} …
Run Code Online (Sandbox Code Playgroud)

c++ templates sfinae class-template c++17

1
推荐指数
1
解决办法
80
查看次数