Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm developing my first EmberJS app after following some tutorials as practice. It simply contains a list of 'tables', 'columns', and 'rows' similar to a database.

Link to the problematic page: http://www.kangarooelectronics.com/fakeDB/#/tables/edit/2

My issue is that when I go to remove a column I get: Object # has no method 'deleteRecord' As I understand this is due to the object I'm iterating through having no references to the controller because of the way I am constructing the array that I use to create my list.

Removing tables works fine, which are listed in the following fashion:

{{#each model itemController='TableList'}}
    <a {{action removeTable this}}>Delete</a>
{{/each}}

I'm iterating through the columns via:

{{#each column in currentColumns itemController='TablesEdit'}}
    <a {{action removeColumn column}}>Drop</a>
{{/each}}

Snippet from FIXTURES object:

FakeDB.Table.FIXTURES = [
    {
        id: 1,
        name: 'Users',
        columns: {
            1:{'colId':1, 'name':'name'},
            2:{'colId':2, 'name':'favorite color'},
            3:{'colId':3, 'name':'phone number'}
        },
// ...snip... //

I am getting 'currentColumns' via:

FakeDB.Table = DS.Model.extend({
    name: DS.attr('string'),
    columns: DS.attr('object'),
    rows: DS.attr('object'),
    currentColumns: function() {
        var newColumns = $.map(this.get('columns'), function(k, v) {
            return [k];
        });
        return newColumns;
    }.property('columns'),
// ..snip.. //

Here you can see my problem... it's obvious that my 'column' isn't going to have any methods from my controller. I tried something like this:

FakeDB.Adapter = DS.FixtureAdapter.extend();

FakeDB.Adapter.map('FakeDB.Table', {
    columns: {embedded: 'load'},
    rows: {embedded: 'load'}
});

FakeDB.Columns = DS.Model.extend({
    colId: DS.attr('integer'),
    name: DS.attr('string')
});

FakeDB.Rows = DS.Model.extend({
    colId: DS.attr('integer'),
    name: DS.attr('string')
});

But I couldn't get {{#each column in columns}} to work with that.

Any suggestions? I'm going to read the docs again and will post back if I find a solution. Thanks!

EDIT: So I think I found another solution, but I'm still running into a little issue.

FakeDB.Table = DS.Model.extend({
    name: DS.attr('string'),
    columns: FakeDB.Columns.find().filter(function(item, index, self) {
        if(item.tableID == 1) { return true; }
    })
});

Still not sure what to replace 'item.tableID == 1' with so that I get items with the tableID referencing to the current page...

Columns are structured as...

FakeDB.Columns.FIXTURES = [
    {
        id: 1,
        tableID: 1,
        name: 'name'
    },
// ...snip... //

But now I get: assertion failed: Your application does not have a 'Store' property defined. Attempts to call 'find' on model classes will fail. Please provide one as with 'YourAppName.Store = DS.Store.extend()'

I am in fact defining a 'Store' property...

share|improve this question
Update: Almost there, removed the columns reference from FakeDB.Table. Created a FakeDB.TablesEditRoute, can read params.table_id. Just have to filter the columns and then it will work (can list all ATM). Then I have to work on the relationships aspect and making it more efficient. – user981408 22 hours ago

1 Answer

I'm developing my first EmberJS app after following some tutorials as practice. It simply contains a list of 'tables', 'columns', and 'rows' similar to a database.

Most databases do contain a list of tables, rows and columns. Most web applications contain a fixed set of tables with pre-defined columns and a dynamic list of rows. If this is your first ember app i would recommend starting with something that keeps you on the happy path.

I am in fact defining a 'Store' property...

True but ember is complaining because store is not available before ember app is initialized. Anything that accesses the store should be in a framework hook of some kind. It can't be used when defining your objects, which wouldn't make a lot of sense anyway.

Probably what you meant to do was make a computed property called columns like this:

FakeDB.Table = DS.Model.extend({
  name: DS.attr('string'),
  columns: function() { 
    FakeDB.Columns.find().filter(function(item, index, self) {
      if(item.tableID == 1) { return true; }
    })
  }.property('')
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.