1

I try to make a project with using of loopback and remote postgresql database. Tables are filled and I see it in pgAdmin.

I have this code:

/models/language.js

var loopback = require('loopback'),
 app = require('../app');


loopback.createModel('languages', {
 id: Number,
 des_id: Number,
 iso: String,
 codepage: String
})


app.model('languages', { dataSource: 'pg' });

(I'm not agree with concept of using one file for storing all model definitions. But I'm agree that LDL is cool! ^_^)

"loopback-explorer" successfully shows my REST's for new model. But when I try to GET something it selects only "id" fields.

[ { id: 1 },
  { id: 4 },
  { id: 6 },
  { id: 7 },
  { id: 8 },
  { id: 9 },
...
]

It counts right number of entities.

This code has no effect of fintering:

app.models.languages.find({
  where: {'des_id': 14360}},
 function(err, langs) {
 console.log(langs)
 });

I get the same amount of data as in previous output.

I tried this

app.models.languages.find({
    fields: {id: false}
  },
  function(err, langs) {
    console.log(langs)
  });

same effect.

I tried to create model without properties defenition:

loopback.createModel('languages', {})

same effect.

but

app.datasources.pg.discoverModelProperties('languages', function(err, props) {
  console.log(props);
})

shows right scheme

Where I'm wrong?

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
zaycker
  • 37
  • 5

1 Answers1

0

By this code:

loopback.createModel('languages', {
    ...
})

I created some object (model definition?) that wasn't used anywhere. Also creator is a base "class" loopback and not instanced applicataion app. And this code:

app.model('languages', { dataSource: 'pg' });

created new model which available in app.models but without any schema definition. That's why I got only id-s and no other fields.

Right way:

var loopback = require('loopback'),
    app = require('../app');

var Langs = app.datasources.pg.createModel('languages', {
    ...
})

app.model(Langs);
zaycker
  • 37
  • 5