Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performing recursive eager loading causes conversion error #158

Closed
tobbe303 opened this issue Jun 8, 2017 · 2 comments
Closed

Performing recursive eager loading causes conversion error #158

tobbe303 opened this issue Jun 8, 2017 · 2 comments

Comments

@tobbe303
Copy link

tobbe303 commented Jun 8, 2017

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!

@aarondl
Copy link
Member

aarondl commented Jun 9, 2017

Thanks for the report. I believe I've fixed this one. If you can confirm using the dev branch I'll make a release with these fixes. That code is really hard to follow (Rob Pike was right about reflection!) so I missed that one when I fixed the other instance :)

@tobbe303
Copy link
Author

tobbe303 commented Jun 9, 2017

Yes, I can confirm the dev branch is now fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants