Friday 14 April 2017

Loopback Model relation is not working

Loopback 2.x

I do not know where I am wrong. I follow all the instructions from official website but still it showing no relations.

Database - Mysql Table Name - Booking and Bidding

Bidding foreign key reference to Booking table - bookingId

My models -

booking.json

    {
      "name": "Booking",
      "base": "PersistedModel",
      "strict": false,
      "idInjection": true,
      "properties": {
        "user_id": {
          "type": "number"
        },
        "orgin": {
          "type": "string"
        },
        "orgin_lat": {
          "type": "string"
        },
        "orgin_lon": {
          "type": "string"
        },
        "destination": {
          "type": "string"
        },
        "dest_lat": {
          "type": "string"
        },
        "dest_lon": {
          "type": "string"
        },
        "parcel_type": {
          "type": "string"
        },
        "volume": {
          "type": "string"
        },
        "weight": {
          "type": "string"
        },
        "price": {
          "type": "string"
        },
        "receiver_phn": {
          "type": "string"
        },
        "payment_mode": {
          "type": "string"
        },
        "booking_status": {
          "type": "string"
        },
        "lang": {
          "type": "string"
        },
        "booking_no": {
          "type": "string"
        },
        "cancel_reason": {
          "type": "string"
        },
        "booking_date": {
          "type": "string"
        },
        "plan_later": {
          "type": "string"
        },
        "created": {
          "type": "string"
        },
        "modified": {
          "type": "string"
        }
      },
      "validations": [],
      "relations": {
          "biddings": {
          "type": "hasMany",
          "model": "Bidding",
          "foreignKey": ""
        }
      },
      "acls": [],
      "methods": {}
    }

bidding.json

{
  "name": "Bidding",
  "base": "PersistedModel",
  "strict": false,
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "myuserId": {
      "type": "number"
    },
    "bookingId": {
      "type": "number"
    },
    "price": {
      "type": "string"
    },
    "message": {
      "type": "string"
    },
    "bid_date": {
      "type": "string"
    },
    "bid_time": {
      "type": "string"
    },
    "lang": {
      "type": "string"
    },
    "created": {
      "type": "string"
    },
    "modified": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {
    "booking": {
      "type": "belongsTo",
      "model": "Booking",
      "foreignKey": ""
    }
  },
  "acls": [],
  "methods": {}
}


via user2968961

No comments:

Post a Comment