This plugin exposes the ability to map columns on other tables to this Model.

See patio.plugins.ColumnMapper.mappedColumn for more information.

Static Properties
PropertyTypeDefault ValueDescription
fetchMappedColumnsOnSavepropertytrue

Boolean flag indicating if mapped columns should be re-fetched on save.

NOTE This can be overridden by passing {reload : false} to the patio.Model#save method.

fetchMappedColumnsOnUpdatepropertytrue

Boolean flag indicating if mapped columns should be re-fetched on update.

NOTE This can be overridden by passing {reload : false} to the patio.Model#update method.

Constructor

Defined plugins/columnMapper.js

mappedColumn Static Function Public


Defined plugins/columnMapper.js

Add a mapped column from another table. This is useful if there columns on another table but you do not want to load the association every time.

For example assume we have an employee and works table. Well we might want the salary from the works table, but do not want to add it to the employee table.

NOTE: mapped columns are READ ONLY.


patio.addModel("employee")
   .oneToOne("works")
   .mappedColumn("salary", "works", {employeeId : patio.sql.identifier("id")});

You can also change the name of the of the column


 patio.addModel("employee")
   .oneToOne("works")
   .mappedColumn("mySalary", "works", {employeeId : patio.sql.identifier("id")}, {
         column : "salary"
   });

If you want to prevent the mapped columns from being reloaded after a save or update you can set the fetchMappedColumnsOnUpdate or fetchMappedColumnsOnSave to false.



var Employee = patio.addModel("employee")
  .oneToOne("works")
  .mappedColumn("mySalary", "works", {employeeId : patio.sql.identifier("id")}, {
         column : "salary"
  });

//prevent the mapped columns from being fetched after a save.
Employee.fetchMappedColumnsOnSave = false;

//prevent the mapped columns from being re-fetched after an update.
Employee.fetchMappedColumnsOnUpdate = false;

You can also override prevent the properties from being reloaded by setting the reload or reloadMapped options when saving or updating.


//prevents entire model from being reloaded including mapped columns
employee.save(null, {reload : false});
employee.update(null, {reload : false});

//just prevents just the mapped columns from being reloaded
employee.save(null, {reloadMapped : false});
employee.update(null, {reloadMapped : false});

Arguments Returns Source
function (name,table,condition,opts){
   opts = opts || {};
   if (name) {
       name = sql.stringToIdentifier(name);
       if (table && condition) {
           opts = comb.merge({joinType: "left", table: table, condition: condition, column: name}, opts);
           this._mappedColumns[name] = opts;
       } else {
           throw new ModelError("mapped column requires a table and join condition");
       }
   }
   return this;
           
}
    

Documentation generated using coddoc.