Git Product home page Git Product logo

Comments (8)

raymondfeng avatar raymondfeng commented on August 16, 2024

LoopBack assumes that there is always a PK. It's required for a lot of APIs to be functional. Is there a reason that your table cannot have a PK?

You can also fake a PK by adding id: true to one of your property definitions.

from loopback-connector-oracle.

vbourgeois avatar vbourgeois commented on August 16, 2024

I'm working on an existing database that doesn't have PK for some reasons and that I can't modify. There are some unique constraints that I could use as PK, but there is nothing related to unique constraint in model.definition.properties[propertyName]. Is there a way to know in the generated model where the field with unique constraint is?

Thanks.

from loopback-connector-oracle.

raymondfeng avatar raymondfeng commented on August 16, 2024

Do you use discovery to build loopback models from oracle tables?

You can always nominate a property as an id (pk) in loopback by setting id to true. It doesn't require a DB PK.

Sent from my iPhone 5

On Jul 16, 2014, at 1:02 AM, vbourgeois [email protected] wrote:

I'm working on an existing database that doesn't have PK for some reasons and that I can't modify. There are some unique constraints that I could use as PK, but there is nothing related to unique constraint in model.definition.properties[propertyName]. Is there a way to know in the generated model where the field with unique constraint is?

Thanks.


Reply to this email directly or view it on GitHub.

from loopback-connector-oracle.

vbourgeois avatar vbourgeois commented on August 16, 2024

Yes I use the "discoverAndBuildModels" method, but it doesn't seem to get the unique constraints I want to use as PK. Does it matter if I select a random property as PK or it will add constraints on it in loopback?

from loopback-connector-oracle.

vbourgeois avatar vbourgeois commented on August 16, 2024

I finally found a way to identify the eligible column for primary key.

Model is built with discoverAndBuildModels and I tried to set the PK manually like this: model.definition.properties[idName].id = true;.
But it's not working, dataSource.idName(modelName); still returns undefined and causes the create method to fail.

How can I set the PK manually?

from loopback-connector-oracle.

raymondfeng avatar raymondfeng commented on August 16, 2024

Can you do the following?

model.definition.rawProperties[idName].id = true;
model.definition.build(true); // Force rebuild the list of properties

from loopback-connector-oracle.

vbourgeois avatar vbourgeois commented on August 16, 2024

It's working, PK is set and create method works.
Thank you.

from loopback-connector-oracle.

kaushaldeck avatar kaushaldeck commented on August 16, 2024

I am working with a mongo db collection called users with the following fields : _id (default mongo created pk field), email, username, status.
I have created a model where I have marked email field as the id field. But after going through the full cycle when i run the get query for /users/{id} loopback queries only the _id field but doesnt query the email field (which I have marked as the id field in my model). Can someone help me in changing this?

Thanks

from loopback-connector-oracle.

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.