Is it possible to inject a service into a model.
The issue is that I have a product.cfc and a productService.cfc. I have a function that I need to be in the product.cfc model to get a list of attributes and format them a specific way.
However I need to check those attributes against a categoryService function as the attributes are conditional to the specific category selected.
Is it possible to inject the categoryService into my base product.cfc model?
I tried the basic ways I know how but it gave me errors.
Suggestions? Am I missing the obvious?
Can you show the code you tried and the error you received. I’ve injected services in models all the time.
Thanks!
~Brad
ColdBox Platform Evangelist
Ortus Solutions, Corp
E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com
Yes it is but make sure you have persist=“false” on the property.
I do use persist=false, getters&setters false but i still get an error.
Here are the snippets - note the categoryService.getGunCategories() in the product.cfc – Below is the error output
if I hard code the list of IDs & remove the property, the system works perfectly, but if inject the service, i get an error. Keep in mind, that I inject services into other services all the time via the service.cfc layer but this is the first time i needed to do it via the model itself.
product.cfc
component name=“product” persistent=“true” entityname=“product” table=“product” batchsize=“25” cachename=“product” cacheuse=“read-write” datasource=“vencommerce” {
property name=“categoryService” inject=“model:category.categoryService” setter=“false” getter=“false” persist=“false”;
//Primary Key
property name=“productID” fieldtype=“id” generator=“native” setter=“false”;
property name=“quantity” ormtype=“integer” default=“0” notnull=“true”;
If you turn on ORM sql logging, what is the actual error?
turns out its not persist=false its persistent=“false” - my bad
to clarify - the categoryService was being called into the SQL statement on execute. it was treating it like a field which I knew was the case but I couldn’t figure out how to tell railo not use use it in the column. all fixed now