node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

Column named "model" crashes

Open jasonals opened this issue 13 years ago • 2 comments

Crashes when trying to access table with column named "model"

[email protected] [email protected]

Problem here

    Object.defineProperty(instance, "model", {
        value: function (cb) {
            return Model;
        },
        enumerable: false
    });

Trace

C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\pg\lib\client.js:160
      throw error;
            ^
TypeError: Cannot redefine property: model
  at Function.defineProperty (native)
  at new Instance (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\orm\lib\Instance.js:596:9)
  at Model.createInstance (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\orm\lib\Model.js:87:18)
  at C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\orm\lib\Model.js:386:13
  at Object.exports.get (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\orm\lib\Singleton.js:27:2)
  at Object.ChainFind.newInstance (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\orm\lib\Model.js:382:15)
  at createInstance (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\orm\lib\ChainFind.js:153:14)
  at C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\orm\lib\ChainFind.js:163:6
  at [object Object].callback (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\orm\lib\Drivers\DML\postgres.js:97:6)
  at [object Object].Query.handleReadyForQuery (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\pg\lib\query.js:80:10)
  at [object Object].<anonymous> (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\pg\lib\client.js:151:26)
  at [object Object].EventEmitter.emit (events.js:117:20)
  at [object Object].<anonymous> (C:\Users\Jason\Dropbox\websites\justlooking246v3\node_modules\pg\lib\connection.js:97:12)
  at Socket.EventEmitter.emit (events.js:95:17)
  at Socket.<anonymous> (_stream_readable.js:738:14)
  at Socket.EventEmitter.emit (events.js:92:17)
  at emitReadable_ (_stream_readable.js:408:10)
  at emitReadable (_stream_readable.js:404:5)
  at readableAddChunk (_stream_readable.js:165:9)
  at Socket.Readable.push (_stream_readable.js:127:10)
  at TCP.onread (net.js:526:21)

jasonals avatar Sep 20 '13 19:09 jasonals

The same effect would be possible by defining a column with any of the following names. This is due to the need for internally visible properties used to handle instances. The model property was implemented to allow you to specify something along the lines of model.find({ relation: Instance }) without a problem.

Example Failure Names

  • on
  • save
  • saved
  • remove
  • isInstance
  • isPersisted
  • isShell
  • validate
  • model
  • __singleton_uid

A crash can also be caused when implementing an extra method, or relationship with any of these names.

As far as I can see, this is a Won't-Fix and the use of these names should be avoided in models to avoid the problem.

notheotherben avatar Sep 20 '13 19:09 notheotherben

Thanks

jasonals avatar Sep 20 '13 19:09 jasonals