question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with passing Models[] into .link() method.

See original GitHub issue

So I have a situation here where I have a function for dynamically importing models into an array to then be linked to the database instance. I’m getting this error:

  Type 'Model' is missing the following properties from type 'typeof Model': prototype, table, timestamps, fields, and 30 more.
database.link(await getModels("./models"));

So my function for dynamically importing is:

import { Model } from "https://deno.land/x/denodb/mod.ts";
import { walk } from "https://deno.land/std/fs/walk.ts";

const getModels = async (path: string): Promise<Model[]> => {
  const models: Model[] = [];

  for await (const file of walk(path)) {
    if (file.isFile) {
      const module = await import(`./${file.path}`);
      models.push(module.default);
    }
  }

  return Promise.resolve(models);
};

and the call to link is:

database.link(await getModels("./models"));

I did try:

const models: Model[] = await getModels("./models");
database.link(models);

but that had the same error.

I suspect it’s to do with the link method requiring models to be of (typeof Model)[] which is function. But I can’t seem to get it to work.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TokenChingycommented, May 21, 2020

Actually never mind, I was using DATA_TYPE.string and not DATA_TYPES.STRING. Could you possibly make the documentation better? I’m having to dig into the source code to get answers.

EDIT: If I have time, and find this works well, I’ll make a PR for documentation if that’s okay?

0reactions
eveningkidcommented, May 21, 2020

Also, just added another commit (5d4b631d877eb6c960bc669939752756a8da1e35) that should bring some hints this time when you type DATA_TYPES.something.

If you reload the library, you should get the update!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET MVC Passing models by ActionLink - Stack Overflow
You can't pass model using ActionLink · MVC4 allows you to pass the model automatically through URL variables, which is seen my second...
Read more >
Passing variables between pages using URL GET or POST ...
A query sting can be formatted with a link or a form can be used with get method to pass variables between pages....
Read more >
Accessing Your Model's Data from a New Controller
In this section, you'll create a new `MoviesController` class and write code that retrieves the movie data and displays it in the browser ......
Read more >
Pass data between destinations - Android Developers
To pass data between destinations, first define the argument by adding it to the destination that receives it by following these steps:.
Read more >
Routing - Laravel - The PHP Framework For Web Artisans
Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes. For example, instead of injecting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found