I am new in Backendless and I have read all the manuals about relations, but still not sure how to create san intermediate table between two tables.
For instance, I have table called users and tables called Events. A user can subscribe to events. So I want new table UserEvents, which has user_id and event_id. Also, how would I retrieve all events added by user? In other words, how to do joins in Backendless?(I suppose there is no joins and everything much simpler though).
Thank you very much!
There are two separate questions at hand here:
How to create relationships between objects?
How to load objects created by a user?
Let's start with the first one:
How to create relationships between objects?
When you work with Backendless it is important to think in terms of objects and not tables. For example if there is an entity called Order and it contains a collection of OrderItem objects, then THAT is your data structure. You do not need to pre-create tables in console – Backendless will do it for you the very first time you save an Order object which has a collection of OrderItems. However, if you would like to do it by hand in our Console, here are the steps:
Login to console, select an app, click on Data
Create table Order (it is better to name tables in the singular form - so Order, not Orders).
When you create a new table (click the "+" button in the lower-left corner), console will prompt you to switch to Schema Editor so you can add some data columns. A column would correspond to a property in the class which represents a record from the table.
Now that the Order table is in place, repeat the process for the OrderItem table.
Once both tables exist, we need to "link" the tables together. That link would establish a relationship which can be either one-to-one or one-to-many. To do this, select the Order table and click the Table Schema and Permissions red button in the upper right corner.
Click the Add Relationship button.
In the popup that appears, you will need to create a property which will contain a collection of order item objects. Name that property "orderItems" (it is okay to make it plural here). On the right side of the popup select the OrderItem table. In the Multiplicity drop-down select Many.
Click Save. At this point the relationship is established.
To see it working you can either use the code generation module which will give you all the source code for working with the tables. Click the Code Generation icon. In the Android section, select either Eclipse or IDEA in the IDE block, then click the Java classes for defined data tables option. Click Download Project. Backendless will generate a ZIP file with the source code for the client-side classes that will let you perform a full CRUD (Create, Retrieve, Update, Delete) range of operations on your tables.
The documentation describes how to work with related data. For instance, see the approaches and API for retrieving related objects.
Things are simpler when it comes to the question of how to load objects created by a user. So we come to the second question:
How to load objects created by a user?
The approach described above works equally well for linking the built-in Users table with any other table. However, specifically with the Users table, that link/relationship is not necessary. The reason for this is Backendless automatically tags any created object with the ID of the "owner", that is the user who created the object. That "tag" can be seen with the special ownerId property in the Users table. To enable retrieval of the objects which belong to the user, we need to modify the security permissions for the table which contains the objects created by users:
Login to console, select your app and click the Data icon.
Select the table with the objects created by users.
Click the Table Security and Permissions red button in the upper right corner of the screen.
Click the Role Permissions menu item.
Locate the cell at the intersection of the Find column and the AuthenticatedUser row. Click the cell until you see a red cross.
Repeat the previous step for the intersection of the Find column and the NotAuthenticatedUser row.
At this point you restricted all access to your table for both authenticated and not-authenticated (guest) users. The next step will allow the owners to retrieve the objects which they created.
Click the Owner Policy menu item.
Click the cell in the Find column until there is a green check mark.
At this point when you call any of the Find methods on that table, Backendless will return only the objects which belong to the currently logged in user.
Related
We have two teams working on system related issues and my Access database has one table for each teams open issues. I have created a query that matches issues from each list based on the system name. The query is returning potential matches correctly.
From there, I need to be able to review each "match" and select yes or no on a dropdown to confirm if both teams are working the same issue in order to quickly and easily reduce redundancies. I would prefer to review each result in a form format and have figured out how to add a dropdown box with the yes/no options; however, once I've validated each item, I'd like to filter the results down to only show the items that have been designated as "yes".
That's where I'm stuck. The form is not currently saving the results, including the dropdown info, to a table from what I can see.
How can I get the form to load to a table (or query) in order to filter out the "no" responses?
Try converting your query to an append query or an update query. Create a new table that this query adds data to, and in that table create a new field called "YesNo" or something like that. Put that new field from your table as a control source for your dropdown and should add a value in the "YesNo" field in your new table based on what you select. I'm not sure what value will be added to the table, I did something similar with a check box, when it's clicked it adds a "-1" and when it's unclicked, it adds a 0. Then I run a report that selects records based on the value in that field. I'm assuming the dropdown would work in a similar way but not a 100% sure. Hope I understood your issue, I'm no expert at access but I ran into the opposite issue recently where I didn't want the form to save the results.
You are building an MVC5 EF6 application where the user will add musical albums. A musical album has artist, record label, and category foreign keys which are each represented my their own respective models. On the create album page, the user will select through a drop downs the record label, category and artist. What happens if that artist or record label hasn't been entered yet?
Does the user have to go to the artist or record label view to add it first, then go back to the album page to create the album? Is there a better way to optimize the user process flow?
I had considered using a UI accordion that would be in the album view which would have panels for the album, artist, record label and category models. The artist, record label and category panels would start collapsed. If the user selects "Other" in the drop down for the artist, record label, category , the respective panel would expand and give the user the opportunity to enter the necessary fields to create the record label on the fly. Is this a bad idea? Are there other options I haven't considered that make the process easy for the user?
There are really only two options here:
Let the input form allow a new entry for Record Label, etc. This opens up the possibility of course of duplicate entries (spelling, abbreviation, etc.)
Create another form(s) where you manage those foreign keys, allowing someone to add a new label, artist, etc. The same possibility of duplication exists, however you might be able to introduce some fuzzy logic to search for similar names when an entry is added.
Either of these methods could also incorporate moderation, forcing new entries to be vetted by you or by some other entity, but of course that takes time. The biggest factor for me in making that decision would be whether or not the users of the system could be trusted to make intelligent decisions. (ie find an existing name and use that rather than just keep duplicating)
As far as the design, that's highly preferential and doesn't really have a correct answer. The best solution there is to make a mock up and have someone unfamiliar with the project use the site and get their feedback, and make changes accordingly.
Okay so I'm making a app for fun to get a hang of things. This app is supposed to allow a user to input the number of times he or she has been paid from a client and which account/card number he or she used for the payment. The way I have this set up in CoreData is I have an entity for Client which contains:
details
name
entryId
sectionId
numberOfPayments
details is another cell type that I lets out in the picture that allows the user to input details about the client. I also have an entity for Payments that acts as a many to one relationship to Client that holds the amount and account number given that there can be many.
What I have trouble with is accessing the tableview to save all the data when the done button is hit. I was thinking about a nested for loop that would go through each section and for each row it will save the data accordingly like for Rob through an if statement it will know the first row is a part of the Client entity and every row after would be apart of the Payments entity as relationships. How would I access these individual cells? Is it possible to have this much flexibility with TableView or should I take a different approach.
I recently asked this question about how best to retrieve and display in a tableview the titles my FRC is using for section headers.
Following a line of research suggested by #Mike Pollard in the second answer to my question, I ran across this question and was immediately struck by the similarity to my situation, and by the 4th answer, posted by #aroth.
Aroth's approach certainly appears sound, and I've created a new Category entity. Specifically, Category has a to-many relationship with Item, and Item has a to-one relationship with Category. However I'm having trouble understanding one aspect implicit in his proposed solution, and, more fundamentally, in this relationship:
In my case, both Category(s) and Item(s)--"Item" is called "ListActivity" in my case, but "Item" will do for illustration purposes-- will be named via two corresponding user input fields, which seems like it could result in multiple entries of the same name in the Category list.
My question:
How can I ensure that when I fetch a list of Categories that I get a singular instance of each category, i.e., one category per row in the tableview, with no repeats? Will Core Data automatically assign each new incoming Item to a singular instance of the appropriate Category via the relationship? Or will it somehow test for and winnow the list down to one entry per Category name upon receiving the fetch request? Or must the filtering be done with a predicate in the fetch request?
Thanks!
Core Data will do what you tell it to. This sounds like an issue related to you creating content in your data store rather than an issue with the FRC and table view. It's your responsibility to search for and reuse existing objects rather than creating duplicates and adding them to the store - indeed, only you (your code) knows what constitutes a duplicate.
So, basically, as you create new items, use a fetch request and predicate to find the suitable existing category (or suggest categories based on partially entered names). Then, either connect to the existing category or create a new one.
I have a custom membership provider which I extended - added a couple of fields, first name, last name, adress, zip code and city.
now, these fields reside in the aspnet_Membership table so that I can easily access them when using the static Membership asp.net class.
now, I want to be able so save customer purchase order data (first name, last name, adress, zip code and city) to the database.
should I in my order model/table use a new set of fields - first name, last name, adress, zip code, city or should I create a relationship between my asp_Membershihp table and my Orders table?
Also, If i have dupe data, once a users asks for his account to be removed I wont have any orphan rows in my Orders table if I use the first method.
so, which is best, to have the user data, first name, last name, adress, zipcode, city in only one table and create a relationship between aspnet_Membership table and Orders table OR create the dupe fields in my Orders table with no relationship to the aspnet_Membership table? Pros cons?
Thanks!
/P
In this scenario, i would rather have the relationship.
Also being the data you are storing Orders (i assume at least, from the name :)) i would maintain a separate set of data on the Order, so one would optionally be able to specify different billing/shipping data than it's Identity on the site.
Another valid reason for duplicate at least some data on the Order table is to have all the necessary data relevant to an Order in the table, thus avoiding problems if the Client request his data to be deleted, and maintain the original values for that data on the order if the customer data were to change in time.
If you are able to, though, you should not actually delete User data, but have a field in which you specify if the User isActive or isDeleted.