Skip to content

Create sanity check to prevent column name and relation names from clashing #12

@sc68cal

Description

@sc68cal

I made an oopsie

    try repo.createTable(
        "foo",
        &.{
            t.primaryKey("id", .{}),
            t.column("name", .string, .{ .index = true }),
            t.column("prefix", .string, .{ .index = true }),
            t.timestamps(.{}),
        },
        .{},
    );

    try repo.createTable(
        "bar",
        &.{
            t.primaryKey("id", .{}),
            t.column("number", .string, .{ .index = true }),
            t.column(
                "foo",
                .integer,
                .{ .reference = .{ "foo", "id" } },
            ),
            t.timestamps(.{}),
        },
        .{},
    );

The generated Schema.zig then ended up creating Bar with a .relations that had a .foo as well as having a foo that was part of the object, when it should have been foo_id, and that caused the following error when I tried to do a query that called include

error: duplicate struct field name foo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions