Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending models broken? #3

Closed
digitalscientists opened this issue Feb 21, 2011 · 4 comments
Closed

Extending models broken? #3

digitalscientists opened this issue Feb 21, 2011 · 4 comments

Comments

@digitalscientists
Copy link

In my attempts model extensions defined in a model's methods are not reachable as defined in the readme, including using the human model example.

@jefftriplett
Copy link

I added a m = Object(); to fix it.

@coomsie
Copy link

coomsie commented May 1, 2011

mmm,

I can't seem to get this to work either, not sure what you did to sort it?

CODE BELOW FAILS

Titanium.include('joli.js');

joli.connection = new joli.Connection('joli_example');

var models = (function() {
m = Object();
m.human = new joli.model({
table: 'human',
columns: {
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
city_id: 'INTEGER',
first_name: 'TEXT',
last_name: 'TEXT'
}
,
methods: {
move: function(newCityName) {
// search for the city id
var city = joli.models.get('city').findOneBy('name', newCityName);

    if (!city) {
      throw 'Could not find a city with this name!';
    } else {
      this.city_id = city.id;
    }
  }
}

});

m.city = new joli.model({
table: 'city',
columns: {
id: 'INTEGER',
country_id: 'INTEGER',
name: 'TEXT',
description: 'TEXT'
}
});

m.country = new joli.model({
table: 'country',
columns: {
id: 'INTEGER',
name: 'TEXT'
}
});

m.searches = new joli.model({
table: 'searches',
columns: {
id: 'INTEGER PRIMARY KEY AUTOINCREMENT',
name: 'TEXT',
}
});

return m;
})();

joli.models.initialize();

///Inserting data can be done using the newRecord() method of a model:

// // create the record (not persisted)
var john = models.human.newRecord({
first_name: 'John',
last_name: 'Doe'
});

// move him to New York
john.move('New York');

// persist it
john.save();

//other way

var john = new joli.record(models.human);
john.fromArray({
first_name: 'John',
last_name: 'Doe'
});

// move him to New York
john.move('New York');

// persist it
john.save();

var q = new joli.query()
.select('human.*')
.from('human')
.order(['last_name desc', 'first_name asc']);

// if (win.city_id) {
// q.where('city_id = ?', win.city_id);
// }
//
// if (win.last_name) {
// q.where('last_name LIKE ?', '%' + win.last_name + '%');
// }
//
// if (win.city_name) {
// q.where('city.name = ?', win.city_name);
// q.join('city', 'city.id', 'human.city_id');
// }

var humans = q.execute();

Ti.API.info(humans);

@rchandarana
Copy link

I can't get it to work either. Any fixes available?

@xavierlacot
Copy link
Owner

Hi everybody,

Sorry for letting this bug for so long time. I have just pushed a fix, and adapted the documentation: 40ef6ec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants