You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the Mysql World-database as example to test Orm. All the examples for fields are lowercase. Testing with find returned an empty array but the count was correct. It took me a long time to find out that the field defs in MySql table where mixed case. The empty array was not really helping... It also could suggest the find was empty? An error that the fieldname was not found would have been more helpfull?
I did not express correctly. When I said you can define the properties as you want, I meant as you need. Your example shows that the driver you're using is case sensitive. I never thought about that. Since ORM does not inspect tables before querying, it doesn't know the properties case. What database are you using?
I think it is. I just found that when escaping property names in queries, postgresql is case sensitive. If I don't escape them, it's insensitive... fuck.
I can't do nothing about this, unless I add an option to perform queries without quoting identifiers (table names and column names). This will probably bite me in the future, I would prefer to keep it as it is. You have to define your properties as you have them in database. I don't like having ucfirst() on columns but if you like it, you probably also like it in db.define().
I can't do nothing about this, unless I add an option to perform queries without quoting identifiers (table names and column names). This will probably bite me in the future, I would prefer to keep it as it is.
It will, when someone decides to have a field called select or any one of these.
@GoNode5: Not really sure what's in your databse, so I did some testing of my own:
@dxg I really dont understand the cache thing I have to study your example:
I installed MySql locally, included was an database called: World, wich include an allready created and filled table Country: CREATE TABLE country ( Code char(3) NOT NULL DEFAULT '', Name char(52) NOT NULL DEFAULT '',
You can have mixed case fieldname's in Mysql apperantly... I took the ORM example where fieldnames all are lowercase. These leads to the null showed... The sql query apperently don't care about mixed case (SELECT * FROM country WHERE name LIKE 'n%' showed by node-mysql ) so why do I get an null ?
Ignore the caching thing; it's not the issue you've hit..
I finally understand. I also recreated your table, and got the same problem you did with mysql.
ORM is case sensitive. Some databases are/arent.
This is where the confusion comes from.
@dresende: from what I can see, the data from the database is being discarded here due to different case.
If the user calls Model.sync() there won't be a problem, but if the table is pre-existing, and with different column case, it will continue to trip people up..
I'm not sure of a good solution, will have a think.
EDIT:
SELECT`name`FROM country WHERE`name`LIKE'n%';
name: Norway
SELECT`Name`FROM country WHERE`Name`LIKE'n%';
Name: Norway
Hmm so the database is returning the right thing. The issue lies either in the mysql driver or ORM. Will continue investigating tomorrow..
@dxg thnx... well explained your english is much better... As said before, I think its a mismatch between the results set and the fields in the model. Although Mysql use mixcased you can't have 2 fields like Test and test... So like the query that only use lowercase (SELECT * FROM country WHERE name LIKE 'n%' ) you should lowercase the match between the result fields and the model fields... then it doesn't matter wether the model or sql or table/colums uses mixcase
Mysql driver returns the columns right, as were defined when creating the table. ORM is case sensitive in this case because js object keys are case sensitive. I'm not sure it will be easy to make it insensitive.
since association properties arent created when you call new (but they are when you call find/get, or if you call new and supply world_id).
It sounds like models should have a list of all defined properties to make this more consistent and less error prone, rather than compiling the list each time.
It also sounds like you'd need such a list to implement the select col1, col2.. behaviour, so we should win all round :)
(orm/mysql) SELECT Code, Code, Name, Region, Continent FROM country
WHERE name LIKE 'n%'
ANT
Netherlands Antilles
{"Code":"ANT","Name":"Netherlands Antilles","Region":"Caribbean","Continent":"No
rth America"}
Primary keys are not defined in the properties. The primary key is auto included by ORM. If you add it to the properties it will be duplicated and probably fail a lot.
Activity
dresende commentedon Apr 9, 2013
I think you can define the model properties in any case you want. I'm not sure if it will look for the column as you defined it. I'm going to check.
GoNode5 commentedon Apr 9, 2013
Country.find( {Name:orm.like("n%") }, function (err, countries) {
console.log(countries[0].Name);
// console output: Netherlands Antilles
Country.find( {name:orm.like("n%") }, function (err, countries) {
console.log(countries[0].name);
// console output: null
dresende commentedon Apr 9, 2013
I did not express correctly. When I said you can define the properties as you want, I meant as you need. Your example shows that the driver you're using is case sensitive. I never thought about that. Since ORM does not inspect tables before querying, it doesn't know the properties case. What database are you using?
dresende commentedon Apr 9, 2013
Is it postgresql?
dresende commentedon Apr 9, 2013
I think it is. I just found that when escaping property names in queries, postgresql is case sensitive. If I don't escape them, it's insensitive... fuck.
dresende commentedon Apr 9, 2013
I can't do nothing about this, unless I add an option to perform queries without quoting identifiers (table names and column names). This will probably bite me in the future, I would prefer to keep it as it is. You have to define your properties as you have them in database. I don't like having
ucfirst()on columns but if you like it, you probably also like it indb.define().GoNode5 commentedon Apr 9, 2013
i wrote I used the Mysql ... ucfirst is not needed.... I would prefer rather an error message.
Querie's seems to be case inseniitive. in both cases the sql is the same
(orm/mysql) SELECT * FROM
countryWHEREnameLIKE 'n%'somehow the resultset is not matched... could you not make this always lowercase
dresende commentedon Apr 9, 2013
I don't seem to have a problem with mysql. Are you sure
erris null ? When I tested with postgresql it returned me an error.dresende commentedon Apr 9, 2013
Please post mysql server version and orm version.
GoNode5 commentedon Apr 9, 2013
mysql Ver 14.14 Distrib 5.6.10, for Win64 (x86_64)
2.0.8 (did a fresh new install to a new dir / npm install orm
var orm = require("orm");
orm.connect("mysql://_:_@localhost/world", function (err, db) {
if (err) throw err;
var Country2 = db.define("country", {
Code : { type: "text", size: 3 },
Name : { type: "text", size: 52 }
});
Country.find( {Name:orm.like("n%") }, function (err, countries) {
console.log(countries[0].name);
console.log(countries[0].Name);
});
Country2.find( {Name:orm.like("n%") }, function (err, countries) {
console.log(countries[0].name);
console.log(countries[0].Name);
});
});
dxg commentedon Apr 10, 2013
It will, when someone decides to have a field called
selector any one of these.@GoNode5: Not really sure what's in your databse, so I did some testing of my own:
This is a caching issue; if you disable cache on
Country2it outputs correctly:In this case, the key for the cache is the table name.
GoNode5 commentedon Apr 10, 2013
@dxg I really dont understand the cache thing I have to study your example:
I installed MySql locally, included was an database called: World, wich include an allready created and filled table Country: CREATE TABLE
country(Codechar(3) NOT NULL DEFAULT '',Namechar(52) NOT NULL DEFAULT '',You can have mixed case fieldname's in Mysql apperantly... I took the ORM example where fieldnames all are lowercase. These leads to the null showed... The sql query apperently don't care about mixed case (SELECT * FROM country WHERE name LIKE 'n%' showed by node-mysql ) so why do I get an null ?
dxg commentedon Apr 10, 2013
Ignore the caching thing; it's not the issue you've hit..
I finally understand. I also recreated your table, and got the same problem you did with mysql.
ORM is case sensitive. Some databases are/arent.
This is where the confusion comes from.
@dresende: from what I can see, the data from the database is being discarded here due to different case.
If the user calls
Model.sync()there won't be a problem, but if the table is pre-existing, and with different column case, it will continue to trip people up..I'm not sure of a good solution, will have a think.
EDIT:
Hmm so the database is returning the right thing. The issue lies either in the mysql driver or ORM. Will continue investigating tomorrow..
GoNode5 commentedon Apr 10, 2013
@dxg thnx... well explained your english is much better... As said before, I think its a mismatch between the results set and the fields in the model. Although Mysql use mixcased you can't have 2 fields like Test and test... So like the query that only use lowercase (SELECT * FROM country WHERE name LIKE 'n%' ) you should lowercase the match between the result fields and the model fields... then it doesn't matter wether the model or sql or table/colums uses mixcase
dresende commentedon Apr 10, 2013
Mysql driver returns the columns right, as were defined when creating the table. ORM is case sensitive in this case because js object keys are case sensitive. I'm not sure it will be easy to make it insensitive.
7 remaining items
dresende commentedon Apr 11, 2013
Don't worry, I'm going to change this.
dxg commentedon Apr 11, 2013
Yeah, defined properties [normal+association].
I noticed that sometimes hasOne association properties aren't created:
will print out:
since association properties arent created when you call
new(but they are when you callfind/get, or if you callnewand supplyworld_id).It sounds like models should have a list of all defined properties to make this more consistent and less error prone, rather than compiling the list each time.
It also sounds like you'd need such a list to implement the select col1, col2.. behaviour, so we should win all round :)
dresende commentedon Apr 11, 2013
Yes, I have a change with that list. I'm just fixing this list to have associations.
Changes model.find() queries to specify columns instead of selecting …
dresende commentedon Apr 12, 2013
Please test this change when you can.
GoNode5 commentedon Apr 12, 2013
GoNode5 commentedon Apr 12, 2013
cant you give the model, like methods, an search/find option where you can define searches...
default will be all/*
dresende commentedon Apr 12, 2013
@GoNode5 : you should define the model properties as you have them in the table. In your case, at least
nameshould beName.What do you mean by this? I did not understand your example.
GoNode5 commentedon Apr 12, 2013
error is about 'id' ? Changing from 'name' to 'Name' didnt help. (btw there is no id field, primary key is Code in the country table)
find would be a property of the model where you could predefine column(s) to use in find, instead of define them for every Find
Model.find( [columns /pre defined finds from model / or select all*][ conditions ] [, options ] [
dresende commentedon Apr 12, 2013
If primary key is
Code, you're doing it wrong. Your Country model should be defined like this:GoNode5 commentedon Apr 12, 2013
sorry forget the syntax... now its working the actual query has 2x Code?
(orm/mysql) SELECT
Code,Code,Name,Region,ContinentFROMcountryWHERE
nameLIKE 'n%'ANT
Netherlands Antilles
{"Code":"ANT","Name":"Netherlands Antilles","Region":"Caribbean","Continent":"No
rth America"}
dresende commentedon Apr 12, 2013
You added
id: "Code"but you forgot to removeCodefrom properties.GoNode5 commentedon Apr 13, 2013
it's very confusing... I would rather have:
Code : { type: "text", size: 3,primary-key, unique, required},
Name : { type: "text", size: 52, required },
dresende commentedon Apr 16, 2013
Primary keys are not defined in the properties. The primary key is auto included by ORM. If you add it to the properties it will be duplicated and probably fail a lot.