Coder Social home page Coder Social logo

Custom table name? about openrecord HOT 4 CLOSED

philwaldmann avatar philwaldmann commented on May 27, 2024
Custom table name?

from openrecord.

Comments (4)

arxony avatar arxony commented on May 27, 2024

Yes, you can specify the table name in the global config, but not in the model definition:
{
type : 'postgres',
host : '127.0.0.1',
user : 'user',
password : 'password',
database : 'databasename',
charset : 'utf8',
models : __dirname + '/../models//.js',
migrations: __dirname + '/../migrations/
',
plugins : [],
global : true,
inflection: { backgroundjob_summaries: 'backgroundjob_summary' }
}
The sql table name is 'backgroundjob_summary'.

from openrecord.

PhilWaldmann avatar PhilWaldmann commented on May 27, 2024

Hi,

at the current state it's not possible to overwrite the table name inside the model (for sql types). OpenRecord will read all table columns before it will invoke your model definition method.

The table name is a pluralized version of your model name (with underscores). It takes your model name either from your definition store.Model('Foo', function(){...}), or if you have one file per model it will take your file name.

What @arxony pointed out is a way to overwrite the inflection behavior. For example: you have a model Foo and your table name is also called foo. OpenRecord will search for a table called foos. With the inflection config mentioned above you change that behavior and use table foo instead.

from openrecord.

bs1180 avatar bs1180 commented on May 27, 2024

Thanks for quick response. I can achieve what I'm looking for using the inflection method that @arxony explained, and although a method on the definition itself would be handy, it's not essential. I'll mark this as closed.

Thanks again.

from openrecord.

incompletude avatar incompletude commented on May 27, 2024

It would be nice to have a property on the model to set the table name.

from openrecord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.