Call model method from controller


#1

So in my routes that is setting up the controller, I have this:

`import Ember from ‘ember’; import AuthenticatedRouteMixin from ‘ember-simple-auth/mixins/authenticated-route-mixin’;

export default Ember.Route.extend(AuthenticatedRouteMixin, { beforeModel() { if (!localStorage.dealer) { this.transitionTo(‘dealers’); } },

setupController(controller, model) {
	controller.set('model', model);
	
	controller.set('schedules', this.store.find('sched'));
}

}); `

Then in my controller, I have this:

`import Ember from ‘ember’; import EmberValidations from ‘ember-validations’;

export default Ember.Controller.extend(EmberValidations, { init: function() { this._super();

	// Set validations
	console.log(this.get('model.validations'));
	this.validations = this.get('model').getValidations();
},

}); `

In my model, I have a property called validations that is an object that holds information to validate that model… I also have a method called getValidations that returns this.validations … however I tried everything from this.get('model') and this.validations and this.get('validations')… and nothing will grab that property. I want it listed in the property instead of the controller because then I would have to repeat ALL of the validation rules on the controller that edits the model too… and that just seems repetitive and silly.

I’m use to using Laravel (MVC) where you can inject the model object into the controller… but I’m not sure how to do this in Emberjs. Thank you for any help or insight.


#2

Nevermind, I figured out the best practice in emberjs is to store anything not related to inserting/updating data in the controller (am I correct on this thinking?)