How could save an array values using Model - keystonejs

How can do add an array of values into keystone js Model? Like I need to save a list of name, address and phone number into Model.
Thanks

You can use the types TextArray and NumberArray. They are not yet in the official documentation, but there is a new staging documentaton url
where you can find those fields.
Additional you can have a look at the GitHub issues about creating the array fields and about creating the docs about them.
Update:
If you need several values as a list, I would suggest to create a separate model out the values (name, age, phone, etc.) and then make a Relationship field with many:true. There is no other way for several fields in a list.

Related

how to add dyanmic parent child relationship in jira custom field?

I am trying to migrate some of my bugzilla data to JEERA. I have some custom fields in bugzilla which has dynamic parent-child relationship. for exa-
Suppose I have Labels "India" "China" "Russia",
when I click on Label lets say "India", then it should fetch and show only cities from India and not all cities.
Right now , I am able to create Labels and cities custome fields in jeera but lacking dynamic nature.
I will be thankful, if anyone has any idea over this.
Perhaps Select List (cascading) custom field type would best solution here.
As a bit workaround for relate two custom fields between each other you can use ScriptRunner Behaviours. It's like a Groovy definition for frontend logic. Conceptually:
City field must contains all Cities for all Countries.
Create a Behaviour for a Country field. It means when user will change/select a Country field a Behaviour will be run.
In behaviour write code that will get currently selected country and then fulfil a Cities field based on selected country.
Useful methods: getFieldById(fieldId), formField.getValue(), formField.setFieldOptions(Iterable). API Documentation.
I think #sintasy is right.
If you want N-countries have their own cities, cascading select list just fit your requrement.
If you want N-countries * M-other-things, which have no relation with countries, two select lists will fit your requrement.
If you want more complex feature, then I don't known.

Compute many2many field with values from another model using Odoo developer interface

I need a new field inside Contact model that would hold information about Allowed companies of the related user.
Now there is only field about Currently picked company by that user (and it is not enough for me to make a record rule).
The field I want to copy values from is inside model Users and it is called company_ids.
I’m trying to add this field in the developer mode (Settings > Technical > Fields) like this:
But I’m having trouble with code that would fill my field with values from the another model.
for record in self:
record[("x_company_ids")] = env['res.users'].company_ids
I’m guessing that the record is referring to a record inside Contact model and it does not contain fields from another models like Users. So I can’t figure it out how to reference a field from another model.
Something similar to this: env['res.users'].company_ids?
It is even harder for me because it is many2many field and should always update when the source changes.
Maybe better solution would be to use Automatic action to write values to this field?
I saw some threads like this: Computed many2many field dependencies in Odoo 10.
But it seems like in those cases they had clear connection between the fields and I don't have it. I don't know how to get related user while I'm inside Contact model. I know only how to this oposite way (from user to contact): user.partner_id.id
Here in below given code you haven't specified related user from which you will get company_ids, you have directly accessing company_ids
for record in self:
record[("x_company_ids")] = env['res.users'].company_ids
You can write as following :
for record in self:
record["x_company_ids"] = self.env['res.users'].search([('partner_id','=',record.id)]).company_ids

Entity joining in xml

I have run into a little roadblock in regards to joining mantle entities. I would like to have a single depicting fields from two mantle entities, but am unsuccessful in joining them. Specifically, I have linked a list of party relationships (as contacts) to a single partyId (vendor), with the goal to make a vendor contacts page. However I am unable to link that form-list with the PartyContactMech and ContactMech entities (in order to display email and phone number in the same form-list). More generally, my question is how can one map lists to each other the same way one can map a list to a single object (using entity-find-one and value-field does not work when tried with entity-find)?
There is no need to make a view-entity (join entities) to do that. Simply do a query on the PartyRelationship entity in the main 'actions' part of your screen specifying the toParty (vendor). Then in your Form-List, use 'row-actions' to query the PartyContactMech and so on for each fromPartyId (contact) entry that the previous query returned. Also have a look at the PartyViewEntities file in Mantle USL. There are some helpful view-enties already defined for you there such as PartyToAndRelationship, PartyFromAndRelationship etc. Also note that entity-find-one returns a single "map" (value-field) as it queries on the PK. Whereas entity-find returns a list of maps (list). They are separate query types. If I understand your question correctly.

Get a hash of old attribute values from rails active record

I want to generically access the old attributes that have changed in a model - that is, I want to get a hash of the old attributes values. My code is interested in all attributes that have changed, which may be a different set each time it's run.
I know you can get an array of changed attribute names with
model.changed
and I know you can do
model.attribute_was
to get the old value of an attribute if you know the name, but I can't find a way to programatically combine the two or to otherwise get the set of old values
I'm using it to create news stories about objects, eg
User 'Bob' changed x from a to b
You can use the attributes hash to generate this array:
old = model.changed.map{|attr| model.send("#{attr}_was".to_sym) }

What is the best way to fake a SQL array or list?

I'm building a chatroom application, and I want to keep track of which users are currently in the chatroom. However, I can't just store this array of users (or maybe a list would be better) in a field in one of my records in the Chatroom table.
Obviously one of the SQL data types is not an array, which leads me to this issue: what is the best way to fake/mock array functionality in a SQL database?
It seems there are 3 options:
1: Store the list/array of users as a string separated by commas, and just do some parsing when I want to get it back to an array
2: Since the max amount of users is allowed to be 10, just have 10 extra fields on each Chatroom record representing the users who are currently there
3: Have a new table Userchats, which has two fields, a reference to the chatroom, and a user name
I dunno, which is the best? I'm also open to other options. I'm also using Rails, which seems irrelevant here, but may be of interest.
Option 3 is the best. This is how you do it, in a relational schema. It is also the most flexible and future-proof option.
It can grow easier in width (extra columns say, a date joined, a channel status, a timestamp last talked) and length (extra rows when you decide there now can be 15 users in a room instead of 10).
The proper way to do this is to add an extra table representing an instance of a user being in a chatroom. In most cases, this is probably what you will want to do, since it gives you more flexibility in the types of queries you can do (for instance: list all chatrooms a particular user is in, find the average number of people in each chatroom, etc.) You would just need to add a new table - something like chat_room_users, with a chat_room_id, and a user_id.
If you're deadset on not adding an extra table, then Rails (or more specifically ActiveRecord), does have some functionality to store data structures like arrays in a SQL column. Just set up your column as a string or text type in a Rails migration, and add:
serialize :users
You can then use this column as a normal Ruby array / object, and ActiveRecord will automatically serialize / deserialize this object as you work with it. Keep in mind that's there are a lot of tradeoffs with this approach - you will never be able to query what users are in a particular room using SQL and will instead need to pull all data down to Ruby before working with it.