Skip to content

Performing recursive eager loading causes conversion error #158

Closed
@tobbe303

Description

@tobbe303

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

SQLBoiler v2.4.0

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

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

models.Projects(db, Load("Clients.Permissions"), Where("id=?", 1)).One()

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)

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

CREATE TABLE IF NOT EXISTS `projects` (
  `id` integer NOT NULL,
  `name` varchar(128) NOT NULL,
  UNIQUE KEY `name` (`name`),
  PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `clients` (
  `id` integer NOT NULL,
  `project_id` integer NOT NULL,
  `username` varchar(128) NOT NULL,
  `password` varchar(128) NOT NULL,
  UNIQUE KEY `username` (`username`),
  PRIMARY KEY (`id`),
  FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS `permissions` (
  `id` integer NOT NULL,
  `client_id` integer NOT NULL,
  `resource` varchar(128) NOT NULL,
  `permission` tinyint(2) NOT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY (`client_id`) REFERENCES `clients` (`id`) ON DELETE CASCADE
);

INSERT INTO `projects` (`id`,`name`) VALUES (1,'test project 1');
INSERT INTO `clients` (`id`,`project_id`,`username`,`password`) VALUES (1,1,'john','secret');
INSERT INTO `permissions` (`id`,`client_id`,`resource`,`permission`) VALUES (1,1,'resource 1',1);
INSERT INTO `permissions` (`id`,`client_id`,`resource`,`permission`) VALUES (2,1,'resource 2',1);
INSERT INTO `permissions` (`id`,`client_id`,`resource`,`permission`) VALUES (3,1,'resource 3',2);

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

Currently using MySQL and the following sqlboiler.yml configuration

blacklist:
  - goose_db_version
tinyint-as-bool: true
mysql:
  dbname: test
  host: localhost
  port: 3306
  user: root
  pass:
  sslmode: false

Eager loading a project including clients and permissions as described above produces the following error

panic: interface conversion: interface {} is *models.ClientSlice, not *[]*models.Client

However, understanding there has been some work on the dev branch that may be related I also tested this branch. Now using the All() finisher instead of One() there is no error (master branch fails using either of them).

Thank you in advance and keep up the good work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions