volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.69k stars 539 forks source link

undefined: TypeSlice #148

Closed fluffybonkers closed 7 years ago

fluffybonkers commented 7 years ago

What version of SQLBoiler are you using (sqlboiler --version)?

2.3.0

If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)

Didn't happen at generation time.

If this happened at runtime what code produced the issue? (if not applicable leave blank)

go build -a. Error = undefined: StudentEnglishTestSlice

What is the output of the command above with the -d flag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)

Too much output.

Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)

Basically, I have two offending tables in SQL Server. One is called student the other student_english_test. I generate the SQL Boiler models (that is always awesome, by the way) and when I compile I get the error. If I delete student_english_test table from db schema and re-generate models, the error goes away. I have no idea why I am getting this issue because StudentEnglishTestSlice is defined in student_english_test.go. Table definitions:

CREATE TABLE [dbo].[student](
    [student_pk] [int] IDENTITY(100010,1) NOT NULL,
    [usyd_id] [int] NULL,
    [first_name] [varchar](300) NULL,
    [last_name] [varchar](300) NOT NULL,
    [preferred_name] [varchar](300) NULL,
    [passport_country_id] [int] NOT NULL,
    [birth_country_id] [int] NOT NULL,
    [gender] [varchar](13) NOT NULL,
    [occupation] [varchar](50) NULL,
    [previous_ed_institute] [varchar](50) NULL,
    [passport_number] [varchar](50) NOT NULL,
    [university_email] [varchar](500) NULL,
    [personal_email] [varchar](500) NOT NULL,
 CONSTRAINT [PK_Student] PRIMARY KEY CLUSTERED 
(
    [student_pk] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[student]  WITH CHECK ADD  CONSTRAINT [FK_Student_BirthCountry] FOREIGN KEY([birth_country_id])
REFERENCES [dbo].[meta_country] ([country_pk])
GO

ALTER TABLE [dbo].[student] CHECK CONSTRAINT [FK_Student_BirthCountry]
GO

And:

CREATE TABLE [dbo].[student_english_test](
    [english_test_pk] [int] IDENTITY(1,1) NOT NULL,
    [english_test_type_id] [int] NOT NULL,
    [student_id] [int] NOT NULL,
    [test_date] [date] NOT NULL,
    [verified_score] [bit] NOT NULL,
    [overall_score] [decimal](6, 2) NULL,
    [reading_score] [decimal](6, 2) NULL,
    [writing_score] [decimal](6, 2) NULL,
    [listening_score] [decimal](6, 2) NULL,
    [speaking_score] [decimal](6, 2) NULL,
 CONSTRAINT [PK_EnglishTest_1] PRIMARY KEY CLUSTERED 
(
    [english_test_pk] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_EnglishTest_1] UNIQUE NONCLUSTERED 
(
    [student_id] ASC,
    [english_test_type_id] ASC,
    [test_date] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[student_english_test]  WITH CHECK ADD  CONSTRAINT [FK_EnglishTest_MetaEnglishTest] FOREIGN KEY([english_test_type_id])
REFERENCES [dbo].[meta_english_test] ([english_test_pk])
GO

ALTER TABLE [dbo].[student_english_test] CHECK CONSTRAINT [FK_EnglishTest_MetaEnglishTest]
GO

ALTER TABLE [dbo].[student_english_test]  WITH CHECK ADD  CONSTRAINT [FK_EnglishTest_Student] FOREIGN KEY([student_id])
REFERENCES [dbo].[student] ([student_pk])
GO

ALTER TABLE [dbo].[student_english_test] CHECK CONSTRAINT [FK_EnglishTest_Student]
GO

Offending line in student.go:

// studentR is where relationships are stored.
type studentR struct {
    BirthCountry        *MetaCountry
    PassportCountry     *MetaCountry
    Applications        ApplicationSlice
    StudentEnrolments   StudentEnrolmentSlice
    StudentClasses      StudentClassSlice
    StudentEnglishTests StudentEnglishTestSlice
}

Definition in student_english_test.go:

type (
    // StudentEnglishTestSlice is an alias for a slice of pointers to StudentEnglishTest.
    // This should generally be used opposed to []StudentEnglishTest.
    StudentEnglishTestSlice []*StudentEnglishTest
    // StudentEnglishTestHook is the signature for custom StudentEnglishTest hook methods
    StudentEnglishTestHook func(boil.Executor, *StudentEnglishTest) error

    studentEnglishTestQuery struct {
        *queries.Query
    }
)

Further information. What did you do, what did you expect?

NA

aarondl commented 7 years ago

Your table name ends in Test which makes Go create the filename ..._test.go which only gets compiled when test code runs.