coresmart / persistencejs

persistence.js is an asynchronous Javascript database mapper library. You can use it in the browser, as well on the server (and you can share data models between them).
http://persistencejs.org
1.72k stars 240 forks source link

id column is mandatory #27

Open themitchy opened 13 years ago

themitchy commented 13 years ago

I'm trying a simple task of extracting an identity from a table. That table doesn't have an id column(it's key column is called Key). Persistence generates sql that expects the id column and then fails.

var File = persistence.define('Components', {
    Key: 'TEXT',
    Published: 'TEXT'
});

//...

File.findBy(session, tx, 'Key', sha, function(obj) { ... });

Results in the sql:

SELECT `root`.id AS Components_id, `root`.`Key` AS `Components_Key`, `root`.`Published` AS `Components_Published`
FROM `Components` AS `root`  WHERE (1=1 AND `root`.`Key` = ?) LIMIT 1

Is there any way to suppress the selection of an id column?

zefhemel commented 13 years ago

Currently this is not possible. For simplicity of implementation the identifier is always an automatically generated 'id' field. persistence.js also wasn't really designed to be used with existing database schemas. If have the chance to improve this support, go right ahead :)