Code Monkey home page Code Monkey logo

Comments (5)

jacoblee93 avatar jacoblee93 commented on August 16, 2024

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.

somecallmemike avatar somecallmemike commented on August 16, 2024

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.

jacoblee93 avatar jacoblee93 commented on August 16, 2024

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.

somecallmemike avatar somecallmemike commented on August 16, 2024

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.

jacoblee93 avatar jacoblee93 commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.