What is {nk} in loopback API explorer? - loopbackjs

I'm using loopback3.x. Some of the REST APIs contains {nk}. The description of {nk} is given as "Foreign key for interviews". What is {nk} refers to? What is the difference between {nk} and {fk}?

I think it's related to Nested queries.
May be {nk} stands for nested foreign key.

Related

How can I query Zenodo's related identifiers fields?

The Zenodo open data repository offers a web-based query interface with a sophisticated query language. However, I can't get queries for related identifiers (e.g. a data set that supplements a GiHub repository) to return anything.
For example, for this Unix history repository Zenodo data set, the queries for the corresponding GitHub repository
(related_identifiers.identifier:"https://github.com/dspinellis/unix-history-repo") and the DOI of the publication that documents it
(related_identifiers.identifier:"10.1007/s10664-016-9445-5") return no results. Even simpler queries, such as for data sets whose related identifiers is a DOI (related_identifiers.scheme:doi) or for data sets associated with a supplement relationship (related_identifiers.relation:isSupplementTo) fail to return any results. Other queries, such as for data sets with restricted access rights (accessrights:restricted) or those by a specific creator (creators.orcid:0000-0003-4231-1897) work fine.
It seems that this is a limitation of the current query interface. The query language does not support queries for nested fields, such as the related identifiers. The provided documentation was misleading and has been corrected through this pull request. In addition, a Zenodo developer commented that the corresponding identifiers can be accessed through the related.identifier keyword, for example related.identifier:"10.1109/TSE.2019.2892149".

Doctrine: how to set referenceOne relationship without finding() the referenced document?

we need to create a document which references one document in another collection. We know the id of the document being referenced and that's all we need to know.
our first approach is:
$referencedDocument=$repository->find($referencedId);
$newDocument->setUser($referencedDocument);
now the question is if we can do it somehow without the first line (and hitting the database). In the db (we use Mongo) reference is just an integer field and we know that target id, so finding() the $referencedDocument seems redundant.
We tried to create new User with just an id set, but that gets us an error during persisting.
Thanks!
In one of projects I used something like this:
$categoryReference = $this->getEntityManager()->getReference(ProjectCategory::class, $category['id']);
Thou, if you use Mongo, you probably need to use getDocumentManager()
So, link to doctrine docs. mongo odm 1.0.

LoopBack Model Definition vs json-schema

Newbie: Trying to better understand how Loopback Model Definition relates (if at all) to json-schema. Will I be able to just write a json-schema file and use that as the Loopback Model Definition?
While there are definitely some close similarities between the two, json-schema and LoopBack's model definition are not the same.
If you have existing JSON schemas, you can probably convert those to LoopBack model definitions, but depending on how complex / advanced your schemas are will determine how easy that conversion is.

Doctrine specify logical name for JoinColumn [duplicate]

I'm working on an events site and have a one to many relationship between a production and its performances, when I have a performance object if I need its production id at the moment I have to do
$productionId = $performance->getProduction()->getId();
In cases when I literally just need the production id it seems like a waste to send off another database query to get a value that's already in the object somewhere.
Is there a way round this?
Edit 2013.02.17:
What I wrote below is no longer true. You don't have to do anything in the scenario outlined in the question, because Doctrine is clever enough to load the id fields into related entities, so the proxy objects will already contain the id, and it will not issue another call to the database.
Outdated answer below:
It is possible, but it is unadvised.
The reason behind that, is Doctrine tries to truly adhere to the principle that your entities should form an object graph, where the foreign keys have no place, because they are just "artifacts", that come from the way relational databases work.
You should rewrite the association to be
eager loaded, if you always need the related entity
write a DQL query (preferably on a Repository) to fetch-join the related entity
let it lazy-load the related entity by calling a getter on it
If you are not convinced, and really want to avoid all of the above, there are two ways (that I know of), to get the id of a related object, without triggering a load, and without resorting to tricks like reflection and serialization:
If you already have the object in hand, you can retrieve the inner UnitOfWork object that Doctrine uses internally, and use it's getEntityIdentifier() method, passing it the unloaded entity (the proxy object). It will return you the id, without triggering the lazy-load.
Assuming you have many-to-one relation, with multiple articles belonging to a category:
$articleId = 1;
$article = $em->find('Article', $articleId);
$categoryId = $em->getUnitOfWork()->getEntityIdentifier($article->getCategory());
Coming 2.2, you will be able to use the IDENTITY DQL function, to select just a foreign key, like this:
SELECT IDENTITY(u.Group) AS group_id FROM User u WHERE u.id = ?0
It is already committed to the development versions.
Still, you should really try to stick to one of the "correct" methods.

How to get an entity's key when using django-nonrel on App Engine

I'm using django-nonrel (http://www.allbuttonspressed.com/projects/djangoappengine) on Google App Engine. I have my models etc. setup and everything works great. I had one question though. I want to be able to access an entity's key. Given a model named 'Review', I do Review.objects.get(pk = 1).key() which throws an error (AttributeError).
Is there any way I can get the given entity's key so that I can use it instead of being forced to use the pk/id? I want to use the key as a unique identifier for unique & secret URLS (if someone has a better suggestion to achieve this, I'm all ears).
You can get id by calling object.key().id() which returns a unique key inside python .In templates you can simply call object.key.id . Then you can use get_by_id to get the object
You can get your primary key on django-nonrel from the meta data:
review._meta.pk
or for key name:
key=getattr(review,review._meta.pk.column)
Apparently the 'id' field changes depending whether your on the dev or production server. So this works!
reference:
http://www.b-list.org/weblog/2007/nov/04/working-models/