I have Uploads table.
Uploads has many-to-many relation with Parties table.
the junction table is Uploads_Parties, it contains: upload_id & party_id as fields.
how can i make postgraphile to consider these relation in the schema generation ?
attempts:
many-to-many plugin - https://github.com/graphile-contrib/pg-many-to-many. after adding the plugin no effect was taking place.
smart tags plugin - https://www.graphile.org/postgraphile/make-pg-smart-tags-plugin/ - i tried adding foreign key relation between the Uploads.upload_id -> Uploads_Parties.upload_id, but then postgraphile throw an error.
Server init code
const SmartTagsPlugin = makePgSmartTagsFromFilePlugin(
resolve(__dirname, '../../postgraphile.tags.jsonc'),
);
...
appendPlugins: [
SmartTagsPlugin,
PgManyToManyPlugin]
...
tags.jsonc
"config": {
"class": {
"upload_service.upload": {
"tags": {
"foreignKey": [
"(id) references upload_service.uploads_parties (upload_id)|#fieldName uploadDataSet"
]
}
}
}
}
the solution was the tags.jsonc, only pointing the fk the other way around:
uploads.upload_id <- uploads_parties.upload_id.
"config": {
"class": {
"upload_service.uploads_parties": {
"tags": {
"foreignKey": [
"(upload_id) references upload_service.uploads (id)|#fieldName fileUpload"
]
}
}
}
}
i also have these plugins:
pgSimplifyInflector,
postgraphilePluginConnectionFilter,
pgOrderByRelatedPlugin,
pgAggregatesPlugin,
Related
I have to store some users and their group relations like below
So I am planning to create a collection like below
UserGroupRelation Collections
{
"user":String,
"Group":String"
}
example of collections for Super admin users
{
"user":"Adminuser-1",
"Group":"Group1"
}
{
"user":"Adminuser-1",
"Group":"Group2"
}
{
"user":"Adminuser-1",
"Group":"Group3"
}
where user & Group column is indexed and I will run below kind of query
1.Whenever I want to check whether given user has access to the given group
db.UserGroupRelation.find( { user: "Adminuser-1", Group: "Group2" })
2.Also I want to delete all the association whenever we delete group
db.UserGroupRelation.deleteMany({ Group: "Group2" })
3.Also find all the users of a group
db.UserGroupRelation.find( { Group: "Group2" })
4.Find Hierarchy?, with my Approach I am not able to find
But with this approach I am duplicating lot of data also in real time I may have 10000 groups and 1 million user so there would be performance issue. And with this I am not able to maintain a hierarchy like SuperAdmin->SubAdmin->user of same group
I checked with mongo tree but it is not fitting to this requirement. is there a better way to handle this requirement in mongodb .?
This is the structure your graphic requirements show. It does still lead to repetition though so you will need to change it. Read up on one-many relationships.
{
"superAdmin_ID": "001",
"groups": [
{
"_id": "0",
"groupNumber": "1",
"users": [
{
"_userKey": "1023"
"userName": "Fred"
},
{
"_userKey": "1024"
"userName": "Steve"
}
],
"subAdmin": {
"_adminKey": "55230"
"adminName": "Maverick"
},
},
{
"_id": "1",
"groupNumber": "2",
"users": [
{
"_userKey": "1023"
"userName": "Fred"
},
{
"_userKey": "4026"
"userName": "Ella"
}
],
"subAdmin": {
"_adminKey": "55230"
"adminName": "Maverick"
},
},
{
"_id": "2",
"groupNumber": "3",
"users": [
{
"_userKey": "7026"
"userName": "James"
}
],
"subAdmin": {
"_adminKey": "77780"
"adminName": "Chloe"
},
},
]
}
You can also make subAdmin an array if you need more than one subAdmin within a group.
first of all I am sorry if this has been asked 1st, I searched for this and got few links but wasn't helpful.
I am working on simple chat application created in Angular 4 which has Customer entity and Conversation entity and Message. In The customer => hasAndBelongsToMany => Conversation with MongoDb Connector.
In customer.json
"relations": {
"conversations": {
"type": "hasAndBelongsToMany",
"model": "Conversation"
}
}
In conversation.json
"relations": {
"customers": {
"type": "hasAndBelongsToMany",
"model": "Customer"
}
}
This creates table customerconversation which contains conversationId and customerId
Now basically I want to find conversation for two customer Ids, So I tried following filters but it doesn't seem to work and always returns empty array even though there is conversation having these two customer ids.
let filter = {
where: {
and: [
{
customers: {
inq: [
this.customerId // = 59bb981f35fcc941e8ba64e4
]
}
},
{
customers: {
inq: [
this.authService.getCurrentId() // = 59bb98c735fcc941e8ba68ff
]
}
}
]
}
};
and another without and operator
let filter = {
where: {
customers: {
inq: [
this.customerId, // 59bb981f35fcc941e8ba64e4
this.authService.getCurrentId() // 59bb98c735fcc941e8ba68ff
]
}
}
};
These both returns customer with mentioned Id but with 0 conversations. I know I can get all conversations of specific customer by using include filter for conversations but still those would need to be filtered as I want single conversation of this customer with another specific customer.
You can get the information by grabbing the customer first and then using the relations and include to get the data you need.
Example is based on the assumption that you are writing this using typescript & loopback-sdk-builder on an angular application.
this.customerApi
.getConversations(this.authService.getCurrentId(), {
where: {
customerId: this.customerId
})
.subscribe(result => {
// your logic here
})
First of all I'm new to laravel mongodb collection using jenssegers in laravel 5.0 . I would like to form a collection inside sub collection like below
{
"Uid": 1112,
"AccountNo": 7620424,
"Party": {
"LanguageCode": "en",
"Type": "individual",
"Contact": [
{
"id" : It will be mongo object id How to create?
"Type": "default",
"Person": {
"FullName": "Test Test"
},
{
"id" : It will be mongo object id How to create?
"Type": "default",
"Person": {
"FullName": "Test Test"
},
"MessagingMedium": [
{
"Id": It will be mongo object id How to create?
"Scheme": "mailto",
"URI": "demo1dd122#gmail.com",
"Status": "awaiting.registration"
},
{
"Id": It will be mongo object id How to create?
"Scheme": "mailto",
"URI": "demo1dd122#gmail.com",
"Status": "awaiting.registration"
}
]
}
]
},
}
I have userprofile model
use Jenssegers\Mongodb\Model as Eloquent;
class UserProfile extends Eloquent {
protected $table = 'user_profile';
}
use Jenssegers\Mongodb\Model as Eloquent;
class Contact extends Eloquent {
protected $table = 'contact';
}
I have trying to create user profile after trying to add contacts subcollection to that created userprofile collection like below
$user = UserProfile::create(array('Uid' => $uId, 'AccountNo' => $accNo));
$card = Contact::create(['id' => 123]); //contact mongodb Eloquent
$card->userprofile()->save($card);
But its not working and the collection is not creating
Is that correct and i dont know abount hasmany, embedsmany colleciton
Anyone help me out
You have to use the embedsMany relation. This relation allows you to save arrays of objects (Eloquent objects with their own IDs) into existing documents. The relation will be completely managed by the ORM.
You can declare it like that :
class UserProfile extends Eloquent
{
// No table declaration because this model is only saved in the contact collection
}
class Contact extends Eloquent
{
protected $table = 'contact';
public function userProfiles()
{
return $this->embedsMany('UserProfile');
}
}
If you want to embed only one object into an other, you can use the embedsOne relation.
And, before that, you should take a serious look at the package documentation ;)
My app has a "Categories" model.
Categories can be children of other categories.
So there is a "CategoriesAssociations" model.
Here is the code :
/* api/models/Categories.js */
module.exports = {
attributes: {
name: {
type: "string"
},
parents: {
collection: "categoriesassociations",
via: "child"
},
children: {
collection: "categoriesassociations",
via: "parent"
}
}
}
/* api/models/CategoriesAssociations.js */
module.exports = {
attributes: {
parent: {
model: "categories"
},
child: {
model: "categories"
}
}
}
Now when I use the find route aka /categories I get this :
[
{
"createdAt": "2015-08-24T14:16:46.662Z",
"updatedAt": "2015-08-24T14:24:23.819Z",
"name": null,
"id": "55db274e424996cc7e7512e2"
},
{
"createdAt": "2015-08-24T14:18:29.748Z",
"updatedAt": "2015-08-24T14:18:41.105Z",
"name": "test",
"id": "55db27b5424996cc7e7512e4"
}
]
So no trace of the parents and children properties.
The associations are indeed created in the database for when I request /categories/55db27b5424996cc7e7512e4/children I get this :
[
{
"parent": "55db27b5424996cc7e7512e4",
"child": "55db274e424996cc7e7512e2",
"createdAt": "2015-08-24T14:32:43.429Z",
"updatedAt": "2015-08-24T14:32:43.429Z",
"id": "55db2b0bc97cc73083017f60"
}
]
Sails docs states that the populate configuration key for blueprints defines :
Whether the blueprint controllers should populate model fetches with data from other models which are linked by associations. If you have a lot of data in one-to-many associations, leaving this on may result in very heavy api calls.
The value is true in my project but still, associations attributes don't get populated.
Did I misunderstand the docs or is there a problem with my project?
I use sails 0.11.x
The problem is I'm using sails-permissions which has overrides blueprints' populate config :
sails.config.blueprints.populate = false;
I opened an issue to know why it's done globally and how to fix the problem.
According to the sample code at http://docs.neo4j.org/chunked/2.0.0-M03/rest-api-transactional.html I'm trying to use the MERGE statement.
But when I apply the following statement:
{
"statements": [
{
"statement": "MERGE (p:PERSON { identification }) ON CREATE p SET { properties } ON MATCH p SET { properties } RETURN p",
"parameters": {
"identification": {
"guid": "abc123xyz"
},
"properties": {
"lastName": "Doe",
"firstName": "John"
}
}
}
]
}
it gets back with the following 2 errors:
{ identification }
code: 42000,
status: STATEMENT_EXECUTION_ERROR,
message: Tried to set a property to a collection of mixed types. List(Map(guid -> abc123xyz))
SET { properties }
code: 42001,
status: STATEMENT_SYNTAX_ERROR",
message: =' expected butO' found\n\nThink we should have …
Can this not be done this way (yet) or am I missing something?
Thanks for your help
Daniel
It seems you've discovered a bug. I've reported the issue here:
https://github.com/neo4j/neo4j/issues/975
The issue is that MERGE needs to know the keys you will search on in advance. Passing a map of parameters hides this.
To achieve the same, list each key explicitly. If you still want to pass them all in a single map, you can probably do something like: MERGE (p:Person {name: {merge_map}.name, email: {merge_map}.email}).
Daniel,
I think you have to use SET differently, something like this:
MERGE (p:PERSON { identification })
ON CREATE p SET p={ properties }
ON MATCH p SET p={ properties }
RETURN p
But I'm not sure if that SET overrides all your properties. So it might be that you have to specify them one by one.
{
"statements": [
{
"statement": "MERGE (p:PERSON { guid : {guid} })
ON CREATE p SET p.lastName={lastName},p.firstName={ firstName }
ON MATCH p SET p.lastName={lastName},p.firstName={ firstName }
RETURN p",
"parameters": {
"guid": "abc123xyz",
"lastName": "Doe",
"firstName": "John"
}
}
]
}