I have a bookDatasource. One book has many authors. The collection is displayed in a grid on the book-edit-view. Now I want to sort by authors name. In the collectionDatasource properties I set sortable to true.
How can I do it?
If I understand correctly, you're binding Table and Book Authors using nested datasource, like that:
<datasource id="bookDs"
class="com.company.test.entity.Book"
view="book-edit-view">
<collectionDatasource id="authorsDs" property="authors"/>
</datasource>
If so, first, ensure that Book entity has collection of Authors attribute of ordered type (List or LinkedHashSet). If its not you can change collection type in Studio or manually in Book entity.
Then table column becomes sortable - when user clicks on column header table will sort rows accordingly. Also CUBA Platform will handle saving sorting setting as user settings - so next time user opens the screen table will be sorted.
In order to enable sorting of Book Authors by default you could do it on ORM level. In Studio open entity Book, click on authors attribute and set value name in Order by field in attribute properties panel. This will ensure that any instance of Book entity has authors sorted by name.
Related
I have a new table where one of his fields is related to Table Items. I want to place a filter in one of the function fields Item Category pointing register the Item table, but do not know how this dual role. I hope it was not too confusing ..
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.
So, I have two tables InventTable (for inverntory) and MyCartTable. I want to connect this tables so when I chose some item or items in InventTable to show in MyCartTable's grid. MyCartTable fields are ItemNumber, ProductName, PartyID;
Assuming you are working with AX 2012:
On your MyCartTable, remove the itemNumber field.
Open an other AOT windows go to Data Dictionary - Extended Data Types and locate the itemId data type. Drag and drop this data type on your table. AX will ask if you want to add a foreign key relation. Click yes, this will add a relation to the InventTable to the relations node of your table.
Now on your form, set the JoinSource property of your MyCartTable to you inventTable data source.
If you are having trouble making this work, create a new form with only those two datasources and a minimum amount of controls (like just 2 grids), this allows you to test this more easily.
I have a Core Data application with two entities. One is the Order Entity and the other is the Sales Order Numberentity. The Order entity contains an attribute that basically represents which sales order number it is a part of. I am using an NSFetchedResultsController to try and group this list of orders by sales order number. This is done using the sectionNameKeyPath parameter of the init method of NSFetchedResultsController. However, I want to use attributes of the Sales Order Number entity in the header of the section and this is proving annoying. I could get the first Order in the section and then backtrack from there using the relationship to get the Sales Order Number that it belongs to and then pull attributes from there, but is there a better way to accomplish what I am trying to do?
Sorry if this is unclear.
I'll try to be short and clear with this question.
We have an asp.net mvc app that uses entity framework 4.
Our business model is relatively straightforward:
We have an object (which corresponds to a table) called Photo(s).
That photos table has a handful of columns that match up to properties on the object.
Description,Title,Date etc.
It also has a number columns that reference foreign keys for other tables:
AuthorId,LicenseId etc...
The author and license tables are complex in their own right, with multiple fields (Title,Summary,Date etc.)
I have multiple clients using this application to view their photos. I would like each client to dictate what fields they see when viewing the photos, as well as what fields they see when editing those fields.
My thought is to have tables setup saying client-a should see Field1,Field2 and Field3 when viewing their photos - and client-b should see Field1,Field4 and Field5. But some of these fields are not simply columns in the main photos table, they may be fields in a child table. so Field1 might be: Table.Photos.Title -> which corresponds to an object as: Objects.Photo.title...
but Field3 might be: Table.Licenses.LicenseSummary -> which corresponds to an object as: Objects.Photo.License.LicenseSummary
I'm trying to figure out the methodology that we would use to have a very data driven environment so in the DB I can say, display this object/property (for viewing or editing) and then it would know how to map to whatever table it needs to pull that information. also, during editing... give it some way to pull a list of available values if it is that type of property, and not just a text field.
I'm looking for an example of what this might involve, our model is actually more complex than this, but this is just an idea of what we are trying to accomplish. I don't know if what I'm trying to do is normal, perhaps it involves reflection? This is a new area for me.
If the clients are defining their own custom fields, I would simply give them a Key/Value pairs table.
PhotoID FK
Key string
Value string
Display bool
Note that this essentially amounts to EAV, which comes with its own set of difficulties.
If it's just about permissions on existing fields, you need to capture that information:
PhotoID FK
ClientID FK
FieldName string
Display Bool
You can use this information to inhibit the display of fields in the View. The easiest way to do that would be to use a loop in the View itself, writing the field to the output only if Display is set to true.