Comments (5)
Hi Mike,
I have a couple of ideas:
Is there a property on work_orders called property_id? Nodal will attempt to use that to join the two models.
Are you requiring property in your relationships.js file? What about requiring your relationships.js file in the file you're performing the query?
Otherwise, you could try putting the join method before the where method in your query?
Let me know if one of those solves your issue!
Best,
Jacob
from nodal.
Jacob,
Thanks for the quick response. Answers inline:
Is there a property on work_orders called property_id? Nodal will attempt to use that to join the two models.
Yes, I have a column named property_id in the work_orders table, here is the schema:
"WorkOrder": {
"table": "work_orders",
"columns": [
{"name": "id", "type": "serial", "properties":
{"nullable":false,"primary_key":true,"auto_increment":true}},
{"name": "property_id", "type": "int", "properties": {}},
{"name": "tenant_id", "type": "int", "properties": {}},
{"name": "assigned_to", "type": "int", "properties": {}},
{"name": "name", "type": "string", "properties": {}},
{"name": "description", "type": "string", "properties": {}},
{"name": "budget", "type": "int", "properties": {}},
{"name": "completed_at", "type": "datetime", "properties": {}},
{"name": "status", "type": "int", "properties": {}},
{"name": "created_at", "type": "datetime", "properties": {}},
{"name": "updated_at", "type": "datetime", "properties": {}}
]
},
Are you requiring property in your relationships.js file? What about requiring your relationships.js file in the file you're performing the query?
Yes, property is being required. Here is the contents of the relationships file:
const User = Nodal.require('app/models/user.js');
const Company = Nodal.require('app/models/company.js');
const Property = Nodal.require('app/models/property.js');
const Tenant = Nodal.require('app/models/tenant.js');
const WorkOrder = Nodal.require('app/models/work_order.js');
User.joinsTo(Company, {multiple: false});
Property.joinsTo(User, {multiple: false});
Tenant.joinsTo(Property, {multiple: true});
WorkOrder.joinsTo(Property, {multiple: true});
I also tried removing the relationship for Tenant to see if it was conflicting in some way, which also did not work.
Otherwise, you could try putting the join method before the where method in your query?
Just tried this and no luck.
To add, the Tenant relationship works just fine. The only difference I can tell is that the string I am using to relate tenants does not include an underscore, and I had to change it from tenant to tenants when defining {multiple: true}. Attempting to change work_order to work_orders, or workorders, or WorkOrders, or workOrders also fail.
Thanks again!
from nodal.
Hi Mike,
It actually should be workOrders, I forgot.
I was able to repro by setting up a simple project. If changing the join to workOrders isn't working, you might not be requiring your relationships.js
file in your controller. Try putting:
const Relationships = Nodal.require('app/relationships.js');
at the top of your properties_controller.js
file? Let me know.
Best,
Jacob
from nodal.
Jacob,
Much thanks, setting the join string to 'workOrders' is what fixed it, I guess I had not tried that. Also I did not need to include relationships.js in the properties_controller.js file in order to get it working.
Best Regards!
Michael
from nodal.
Awesome! You should require relationships in your controllers as best practice -- you're probably requiring it in some other file, but if it's not present and you try to do a join, it will fail.
from nodal.
Related Issues (20)
- JSONApi support HOT 1
- orderBy Query Parameter HOT 3
- Fix COR Issues with nodal server HOT 2
- Aggregation on joined relationship column HOT 1
- Setting "global" variables from middleware HOT 1
- Callback being called multiple times in failing controller tests
- AcessToken.verify is not working
- Modelarray.from
- Suggestion for updated wiki docs content for 'Adding new fields columns to an existing model'
- Support for inet model datatype HOT 1
- Create index on multiple column HOT 1
- Multi tenant backend - how to use update and destroy? HOT 1
- nodal built on top of koa or express?
- Conditional join on one to one relationship HOT 10
- Support for MongoDB HOT 1
- cross-spawn-async deprecated
- What is the current development state of this project? HOT 7
- Generate int[] column type? HOT 1
- Db:migrate is ommiting one caracter in the table name for FK relations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodal.