Multiple 'belongsTo' relationships on thinky model - orm

I have two models, User and Capture, where a Capture can be related to multiple users: it is owned, claimed, and processed all by three different users.
User = thinky.createModel 'User',
id: String
displayName: String
email: String
Capture = thinky.createModel 'Capture',
id: String
ownerID: String
processedByID: String
claimedByID: String
created: Date
updated: Date
Capture.belongsTo User.model, 'owner', 'ownerID', 'id'
Capture.belongsTo User.model, 'processedBy', 'processedByID', 'id'
Capture.belongsTo User.model, 'claimedBy', 'claimedByID', 'id'
The owner relationship works, but I cannot get the processedBy and claimedBy relationships to work. I'm querying with .getJoin(), and Thinky has created the secondary indexes on my tables (so it at least knows about the relationships)
What am I doing wrong? How can I get the nested objects to return in my queries?

That's because thinky will join another model once by default (to avoid circular references).
You must be explicit on the links you want to fetch:
Capture.getJoin({owner: true, processedBy: true, claimedBy: true}).run()

Related

Return value 0 when SUM by GROUPBY does not return entity - Sequelize ORM

I'm trying to create a ranking where the projects entity can receive votes, represented by another table, the votes entity. However, when no one voted for project x, the entity votes does not know about the specific project. I'm using ORM Sequelize and I'm using SUM/GROUPBY method to join common records. When there are records, everything goes well. The problem is when there is no vote registered for a given project in the vote table, my wish is that this project without votes, would also be returned with a default value of 0. I've read that it has a default value like "isnull(sum, 0)", something like that, but I don't know where to put it, because in my head the votes entity will have to go back to the projects entity to check which ones didn't add up, so I don't know if it fits in my case.
let response = await Votes.findAll({
limit,
offset,
attributes: ['project', [sequelize.fn('sum', sequelize.col('factor')), 'votes']],
group: ['project', "project_.address" ],
include: [
{
model: Projects,
as: 'project_',
attributes: ["address","name"],
}],
raw: true,
order: [[sequelize.literal('votes'), 'DESC']],
})
return res.json(response);

What is the correct approach to match between multiple entities by equality of their properties?

I have multiple entities and properties of the following kind:
Linkedin company
name
phone
Facebook
facebook_url
name
website_url
phone
website
linkedin_url
facebook_url
phone
Not all entities have all their properties filled.
I want to create a unified dataset that will be based on matched corresponding values between all the entities
I'm considering using a graphdb, neo4j in particular
But if each entity is a node, then I will have to create each relationship by programaticcaly checking the equality of each property to the corresponding property in all other entities.
I also consider using some kind of an sql join, but then it seems like maintaining it when the data model widens will be hard.
What is the write approach to solve this problem?
Which technology is best for this?
Here is one approach for doing that in neo4j. (Stackoverflow is not the right place to ask about the "best" technology for doing something, as that tends to be very subjective.)
You can create unique URL, Phone, Person, and Account nodes, and have each Account connected to the appropriate URL, Phone, and Person nodes.
For example, assuming your 3 sample accounts are related to the same person, here is how you could represent that in the DB:
MERGE (pe:Person {name: 'Jane Doe'})
MERGE (ac_li:Account {type: 'li', id: 'xyz'})
MERGE (ac_fb:Account {type: 'fb', id: 'abc'})
MERGE (ac_si:Account {type: 'site', id: 'foo'})
MERGE (url_li:URL {type: 'li', url: 'http://example.net/xyz'})
MERGE (url_fb:URL {type: 'fb', url: 'http://example.com/abc'})
MERGE (url_si:URL {type: 'site', url: 'http://example.org/foo'})
MERGE (ph:Phone {number: '1234567890'})
MERGE (pe)-[:ACCOUNT]->(ac_li)
MERGE (pe)-[:ACCOUNT]->(ac_fb)
MERGE (pe)-[:ACCOUNT]->(ac_si)
MERGE (ac_li)-[:PHONE]->(ph)
MERGE (ac_fb)-[:URL]->(url_fb)
MERGE (ac_fb)-[:URL]->(url_si)
MERGE (ac_fb)-[:PHONE]->(ph)
MERGE (ac_si)-[:URL]->(url_li)
MERGE (ac_si)-[:URL]->(url_fb)
Then, if you wanted to find all the Account and Person combinations related to a specific URL, you could do this:
MATCH (url:URL)<-[:URL]-(account)<-[:ACCOUNT]-(person)
WHERE url.url = 'http://example.com/abc'
RETURN account, person

How to reuse swagger definitions and remove some of the parameters in it? [duplicate]

This question already has answers here:
Re-using model with different required properties
(2 answers)
Closed 3 years ago.
This is my code:
definitions:
User:
type: object
properties:
id:
type: integer
username:
type: string
first_name:
type: string
last_name:
type: string
password:
type: string
created_at:
type: string
format: date-time
updated_at:
type: string
format: date-time
required:
- username
- first_name
- last_name
- password
/api/users:
post:
description: Add a new user
operationId: store
parameters:
- name: user
description: User object
in: body
required: true
type: string
schema:
$ref: '#/definitions/User'
produces:
- application/json
responses:
"200":
description: Success
properties:
success:
type: boolean
data:
$ref: '#/definitions/User'
As you can see, in the post key under /api/users I used the User definition as my schema on it.
I want to lessen my code so I reused the User definition as my schema. The problem here is that I do not need the id, created_at and updated_at fields.
Is there a way to just inherit some of the fields except the fields mentioned? Also, I would love some suggestions to make it better since I'm trying to learn swagger. Thank you.
As explained in this answer to a similar question:
You would have to define the models separately.
However, you have options for the cases of exclusion and difference.
If you're looking to exclude, which is the easy case, create a model
of with the excluded property, say ModelA. Then define ModelB as
ModelA plus the additional property:
ModelB:
allOf:
- $ref: "#/definitions/ModelA"
- type: object
properties:
id:
type: string
If you're looking to define the difference, follow the same method
above, and exclude the id from ModelA. Then define ModelB and ModelC
as extending ModelA and add the id property to them, each with its own
restrictions. Mind you, JSON Schema can allow you to follow the
original example above for some cases to "override" a definition.
However, since it is not really overriding, and one needs to
understand the concepts of JSON Schema better to not make simple
mistakes, I'd recommend going this path for now.

Unpopulated fields between two Schemas keystone.js

I have two models: Entity and Cabinet. Entity model can have multiple cabinets. One cabinet can have one Entity object.
In my admin UI when I create Cabinet I specify the Entity which the cabinet belongs to.
I have linked Entity to Cabinets and Cabinets to Entity like this:
models/Entity.js
Entity.add({ name: { type: Types.Text, initial: true, label: 'Име' }, cabinets: { type: Types.Relationship, ref: 'Cabinet', many: true }, })
models/Cabinet.js
Cabinet.add({ entity_id: { type: Types.Relationship, ref: 'Entity'}, name: { type: Types.Text, initial: true } })
When I save a new Cabinet and go to Entity list, I expect to see populated cabinet ( I just created )
in the column Cabinets
The column Cabinets in the Entity list view is empty.
Is this a bug in keystone.js or I have missed something?
What you've done here is just create two different models. That being said once you create a new Cabinet you should be able to go into Entities and select that Cabinet from a search/dropdown.
Since this was asked two months ago I'm going to assume you've solved what you were looking for and moved on... but if you are still stuck could you clarify what the rest of your models have and confirm that the Cabinet that you've saved is actually generating?

How do I use the Rally attributecombobox (SDK 2) to show allowed values for Portfolio items?

I need to show the list of allowed values for the State field by Type for Portfolio items. The following code returns URL's instead of values? What am I doing wrong?
var typeCombobox= Ext.create('Ext.Container', {
items: [{
xtype: 'rallyattributecombobox',
model: 'PortfolioItem/FEATURE',
field: 'State',
multiSelect: true,
}],
});
The State attribute on Portfolio Items is an Object. Ideally the following syntax:
field: 'State.Name'
Would be workable - and the constructor would be smart enough to traverse down to the Name field on the Object. I've filed a Defect on this issue on this with Rally Engineering.
The best workaround in the meantime would probably be to use the Ext.form.field.ComboBox and populate the drop down values via a query for valid PI States. Thanks for bringing this to our attention!