How do I create a one to many relationship in Parse? - javascript

I'm trying to set up relationships in parse, but I don't know how. For instance, could I get explicit instructions on how I would link the two tables below?
Branch table consist of objectId, branchName, company, address.
Company table consist of objectId, companyName.
I would like to make a relation between Branch's company field and Company's objectId field in the manner that If I were to pull a record for a specific Branch, the string in the company field would relate to the objectId in the Company table. In real terms 1 company can have multiple branch's, but a branch can only relate to one company.
I have primarily used Access and understand how to make relationships and calls there, but cant figure out how to do it in parse. Do I need to wrote code in my main.js file? Can I do this from the data tab in my dashboard on parse.com?

Relationships in Parse are handled through the Relation data type. To make a class that uses a relation, do the following:
Go into your Parse account, open the app you want to add this class to.
Click on 'Core'.
Click on "data".
Click "Add Class:
For Class #1, call it Company.
Make sure that class is highlighted on the left side, and click "Add Col": Add the companyName as a column, and choose string as the data type.
Do these same instructions again, this time for the Branch class.
Add more columns for the branch class for branchName and address. For the company name relation, do the following:
Add a new column. For the "Select a Type" dropdown, choose "Relation";
On the middle dropdown, it will ask you what you want to relate it to, tell it which Parse class (Company), and on the right, name the column (in your case, it would be "CompanyId").

Related

Do I always have to make one Sequelize model file per table?

I feel like I've progressed a bit far from day 0 in learning node-express + mysql + sequelize, BUT, I'm still confused like if I'm still on the right path.
I'm designing a User role models, one user has only one role model.
Questions are:
do I always have to make one sequelize model file per table?
I read about normalizing database tables, so I'm thinking not making a role_id column in my Users table, and instead make a new table. Is this right?
For instance, I have tables in my scheme design (not sure if it's the correct term, I drew my db design on https://dbdiagram.io/) namely:
Users table
Roles table
UserRoles table
USERS has id(pk), full_name, email.
ROLES has id(pk), description, user_id(foreign key????)
USERROLES has id(pk), user_id, role_id
Yes this will be very useful because:
you'll always be sure where to find a certain model - just find a file with that name in models folder.
you;ll be ale to automatically register all models at once simply by reading all files in a models folder and register them in sequelize
Yes you need a join-table (many-to-many relationship) to link users and roles.

Form based on Product Types

If you have a seller accounts at amazon or ever happened to look at their product upload form, I am sure you must have noticed that for each product type you wish to upload they have a slightly different form.
If you want to sell Table Fans, you are presented with this form
and in case you wish to sell shirts, this is what is presented you.
both forms are different yet do the same thing, i.e. upload products (which has some common and few specific attributes)
What intrigues me about this design is the thought that the end user, a layman, wouldn't be expected to understand jargon like product attributes or its use. You give him a product specific upload form and he will fill it up as necessary.
Looking at a few other carts, take for instance opencart
opencart has one form for all product types and if you need to add a few extra attributes it lays the onus on you (the end user) to first understand what attributes are then work as needed.
(this is opencart's add attributes as needed)
I like the way amazon (and a few other ecommerce site, I believe ebay too does as amazon) worked this up.
I wish to replicate this for my project but honestly speaking I have never seen this before. I do not even understand what do you call this. I tried searching google for "form based on product type" and could not find anything to help me.
Can you please let me know how amazon or ebay do this.
There are many different ways of implementing this. In general, you probably won't be able to do something this complicated with HTML and Javascript alone, you'll need a database and some sort of scripting language like PHP or Ruby on your server to dynamically generate the pages.
It's not clear to me what languages you'd want to use, so I'll give a general description:
On the back-end, in a database I'd create a table for the general product. This table would have a field for product type. Then I would create additional tables for the specific product types, and have these tables store all the additional fields, and the primary key referencing the entry in the main, general product table. I would then create a table for product type, which has the product ID's used in the field in the general product table, and a second field referencing the name of the table in the database that stores this type of product.
The code that is all in common between all types of products, I would have reference the general product table. I would then allow the user to specify the product type, and when this is clicked, send the user to a new page, which would run a script. The script would query the database to retrieve the table name for that data type, and then query the database for a description of additional fields specific to that data type, and display an appropriate form, dynamically generated based on what the database returns.

How to have multiple entries for custom entity?

In our Dynamics CRM online custom project - we've the default ACTIVITIES tab in a custom entity named DocProject's form
ACTIVITIES is able to take multiple entries.
Also, there is NOTES tab in the same form
NOTES is also able to take multiple entries.
Okey, this is done by Dynamics CRM guys. So far so good.
In the same form, we also have a DocProjectActivities lookup field for a custom entity DocProjectActivities
This is a lookup field, hence it has got a 1:N relationship.
Clarification: Our problem is not only about Activities. WKT Notes also behaves similarly. We just need some config which will allow us to make multiple entries for one single field
Problem:
How do one makes sure that this custom entity DocProjectActivities allows to make multiple entries as that for ACTIVITIES & NOTES?
In order to have the associated activity grid like the one in the DocProject entity, you need to enable the option Activities when you're creating the entity (this option can't be changed after the entity is created). This option will create the association with the activities entities and allow you to track all the related phone calls, task, etc.
I think that the problem that you're having is that you defined the DocProjectActivities as an activity entity and therefore you can't have this kind of relationship with the other activities entities. I recommend you to take a look to the differences between Entities and Activity Entities.
Do you mean you need multiple docprojectactivities on the form where you have the activities?
You need to create a 1:n relationship between the form and the docprojectactivities and add the subgrid on that form allowing you to create multiple records for the docprojectactivities.
A lookup field is the '1' side of the 1:n relationship and thus the wrong direction.
Go to docprojectactivities, add a new field type relationship towards the entity you are working on.
Save and publish.
Now go back to the form designer of the entity you need the entries on and go to the tab 'insert'.
Click on sub-grid and select only related records docprojectactivities (entity you are working on)
If you want your custom entity to work as an activity entity, you should have selected "Define as an activity entity" when you created it.
You cannot make a normal lookup field to multiple entities (with the exception being the possibility of creating Customer fields that was introduced in 2016.1).

Partition Key in Azure

Is there any way to set the partition key of an item before inserting it using Javascript?
I've got a Win8 JS app and I want to set the PK so I can have several Cars (for example) linked to an User to be able to given an username, I can query every car that belongs to it. Also, for performance stuff, these Cars should be in the same partition, so, any way?
For example, let's say I've got an User. An User can have several properties, among them, a list of Cars. I've got two tables in Azure Table Storage, one for users and another one for cars and I want to link cars to users through User property "username" (a string) in such a way that I can create a query to select cars whose id is "username". I also want to have performance issues into account so I find desirable to have each set of cars in its own partition asigning them as PK user's username. The question is how can I do this in W8JS app.

Sharepoint Custom List definition and javascript

Hey i want to create a list instance with a definition that defines the following columns.
-Notice StartDate (DateTime)
-Notice EndDate (DateTime)
-Notice Message (Text)
-Notice Colleges (???)
I created the dates and message inside my list def i just have no idea what type should the Colleges column be. I just know it should be a list that represents multiple users.
Also i would like to be able to call a Javascript function to Populate new item inside the list and delete them. Also if i retract the solution how will sharepoint deal with this ? Will items added to the list while the solution is deployed still be there when i redeploy ???
In response to your questions:
You can make Colleagues a 'Person or Group' column which allows for multiple values. Presumably, you want to render a list of all users from which the user can select? If you're doing this server-side, you could bind against SPWeb.AllUsers or SPWeb.Users depending on your needs. Note that neither of those will return all users in your NT domain if that's what you're after (that is a little more complicated).
If you want to manipulate SP lists using Javascript, you should look into using the Client Object Model.
If you retract your solution, the list items will remain there.

Categories