Jhipster display other value when insert connected entites - jhipster

How to display other value when I want to add new Prelection
But when I have to choose Event, there is Event Id. How to change it to name?
Could you give me an example, what should I do?

This is what you got asked by JHipster entity sub generator when you created Prelection entity and added a relationship to Event:
When you display this relationship with Angular, which field from 'Event' do you want to use? (id)
Just enter the field name from the related entity you want to use for presentation (by default it's "id").
For your existing entity Prelection, you can edit .jhipster/Prelection.json and change otherEntityField:
{
"relationshipName": "event",
"otherEntityName": "event",
"relationshipType": "many-to-one",
"relationshipValidateRules": [
"required"
],
"otherEntityField": "name"
},
and then re-generate your entity with yo jhipster:entity Prelection.

Related

Shopware 6 add Custom Field to Admin Search

How can I add a Product Custom Field to the Search in the Admin?
I could not find anything in the Shopware Doku, only for Custom Entitys
I don't think you can add custom fields in the search preferences of your profile yet. You can however add fields by altering the corresponding entry in the table user_config.
For the entry to exist in the database you'll have to first make some changes in the search preferences of your profile.
Then find the entry for the correct user id in user_config. The column value contains the search preferences as json.
Edit that json to your liking, for example to add a custom field of a product to the searchable fields:
[
// ...
{
// ...
"product": {
// ...
"customFields": {
"the_technical_name_of_a_custom_field": {
"_score": 500,
"_searchable": true
}
},
// ...
},
// ...
},
// ...
]

Adding ACL for nested field object in JSON schema object

I am working on specify ACL fields for fields inside objects. I have the validator to check for permission to edit a specific field. For example, the schema looks like this:
"basic_info": {
"properties": {
"cadi_id": {
...
},
"analysis_keywords": {
...
},
"abstract": {
"type": "string",
"title": "Abstract",
"acl": {
"users": ["test#test.org", "test1#test.org"]
}
},
"ana_notes": {
...
},
"conclusion": {
...
}
},
"title": "Basic Information",
"type": "object",
"id": "basic_info",
"required": ["cadi_id"]
}
I have the abstract field with acl. It works fine when the user(not in acl) is editing the abstract field and the validation error is thrown when the user is not in acl.
The problem comes when user(not in acl) is editing other field like conclusion and have the same ValidationError.
When editing any field in basic_info, for example conclusion field, the whole basic_info object is processed in the validator beacuse it's the parent field and now user should be able to edit the conclusion field because there is no acl set. but it gives the ValidationError because we also receive the abstract (which is unchanged) in the basic_info and it goes to validate method and since the user is not in acl it gives ValidationError .
Please let me know what I am missing here to let the user(not in acl) to edit the non acl field?
I tried to get the previous value from the db and check if the controlled field is edited by user or not, but it doesn't seems efficient for this use case and I want to know if there is any native way to do the field level validation. I could not find anything in the docs.

Mongoose and nodejs: about schema and query

I'm building a rest api that allows users to submit and retrieve data produced by surveys: questions are not mandatory and each "submit" could be different from each other. Each submit is a json with data and a "survey id":
{
id: abc123,
surveyid: 123,
array: [],
object: {}
...
}
I have to store this data and allow retrieving and querying.
First approach: going without schema and putting everything in a single collection: it works, but each json field is treated as a "String" and making queries on numeric values is problematic.
Second approach: get questions datatypes for each survey, make/save a mongoose schema on a json file and then keep updated this file.
Something like this, where entry "schema : {}" represent a mongoose schema used for inserting and querying/retrieving data.
[
{
"surveyid" : "123",
"schema" : {
"name": "string",
"username" : "string",
"value" : "number",
"start": "date",
"bool" : "boolean",
...
}
},
{ ... }
]
Hoping this is clear, I've some questions:
Right now I've a single collection for all "submits" and everything is treated as a string. Can I use a mongoose schema, without other modifications, in order to specify that some fields are numeric (or date or whatever)? Is it allowed or is it even a good idea?
Are there any disadvantage using an external json file? Mongoose schemas are loaded at run time when requested or does the service need to be restart when this file is updated?
How to store data with a "schema" that could change often ?
I hope it's clear!
Thank you!

Model relation not working

I'm am trying to figure out how to make the model relation to work in loopback.
I already managed to make one work (with Country hasMany CountryLanguage), this one shows up in the Countries URL.
But When I tried to do another one it doesn't work.
Here is what I'm trying to do :
I have a User model and an Event model, and I want the Event model to be linked with the users that created the event, but I also want an many-to-many relationship to manage the user's subscription to an event. I already tried the hasMany and it doesnt work, well it doesn't show up in the explorer.
About the ownership relation is it just a Event hasOne User ?
UPDATE :
Here is my relation for the users :
"relations": {
"publicEvents": {
"type": "hasAndBelongsToMany",
"model": "PublicEvent",
"foreignKey": ""
},
"privateEvents": {
"type": "hasAndBelongsToMany",
"model": "PrivateEvent",
"foreignKey": ""
}
},
So now the relation for the event is working as in a User can be an owner of an Event, and I also don't know if I chose the correct relation is hasMany enough in this case? (Also there are no relation declared in the event model)
But know I want also the user to be able to subscribe to an Event, I created two model for this PublicSubscriptions and PrivateSubscriptions in which I put:
"properties": {
"userId": {
"type": "string",
"required": true
},
"privateEventId": {
"type": "string",
"required": true
}
},
But I don't know it this the way to do it, I suppose these fields are not required and relation can work this out for me but I don't know which one to choose.
Rather than creating two models for Event you could have a single Event model, and two relations
relation createdEvents : User hasMany Event
relation subscribedEvents : User hasMany Event
Then, you should have some User with specific custom role ("eventCreator" for instance) for the first relation. Users under this role have more rights (like creating an event).
Standard users will only be able to subscribe. Subscriptions can thus be tracked using the second relation.
Hope this helps

mongo update query to ignore few fields in update operation

I am using Nodejs based mongoskin driver for mongo database operation. I want to update my document however don't want to update few fields. Following are more details.
Request for add:
{
"name": "Theme Name",
"description": "Theme Description",
"createdByUserId": "53651221b25521601a5c9530",
}
Request for update:
{
"_id":"53555ef203dabf282b750a81"
"name": "Theme Name",
"categoryId": "53555ef203dabf282b750a81",
"description": "Theme Description",
"createdByUserId": "53651221b25521601a5c9530",
"updatedByUserId": "5675561b25521601a5c9530",
"dateCreated": ISODate("2014-05-19T19:47:26.603Z"),
"dateUpdated": ISODate("2014-05-19T19:49:28.203Z"),
}
I want to ignore following field send by client.
1. createdByUserId
2. dateCreated
For time being I am taking following approach in update operation:
1. Read collection for given _id
2. Read these above two fields from database and update the request and then perform database update operation
Looking help for clean approach.
Your request for update actually does the following: it replaces everything in the document with the values provided by the request (except for the "_id" of course, which is immutable). What you want is what is called a "partial update" in mongosphere. Please have a look into the $set operator. So what you would do is something like:
db.yourcollection.update({"_id":"53555ef203dabf282b750a81"},
{$set:
{
"categoryId":"53555ef203dabf282b750a81",
"updatedByUserId":"5675561b25521601a5c9530",
"dateUpdated":ISODate("2014-05-19T19:49:28.203Z")
}
}
)
As far as I know there is now way of sending a complete document to a mongo[s|d] and tell it to only skip certain fields.

Resources