I'm looking at building a system which will include user created fields which will use Postgresql as the database. I've read that the EAV model for this isn't great and that a jsonb column to store the custom fields will be the best route.
I want the user to be able to build their own queries to the data as well so is the best way to go to store the custom field names in a table and store the actual data in the jsonb column, that way when it comes to building the queries the webapp can query the custom fields table for a reference as to what fields are available and their types?
Tickets
ID
WhenCreated
LastUpdated
CustomProperties {JSON B column, key value pairs where the key names will be stored in the custom fields table}
Customfields
ID
FieldName
WhenCreated
FieldTypeID
FieldTypes
ID
FieldTypeName {String, Date, etc}
Related
I've got a Money class that extends AbstractValueObject with the properties $amount (int) and $currency (string). And I've got an AbstractEntity with a $price property holding an instance of Money. How do I get Typo3 to persist that value object? How do I define the mapping?
Coming from Doctrine, I'd expect it to be persisted in two columns price_amount and price_currency.
Extbase does things a bit differently - so value objects needs to be stored in their own tables and relations between objects are stored by using identifiers just like entities.
The only real difference between Entities and VOs is that the persistence manager will use property values (except the identifier field) when looking for VOs for persistence whereas the identifier will be used on Entities.
So you need to add the database schema for the value object to ext_tables.sql and as the table should contain an auto incrementing uid field as well as the fields you need for your VO. Ensure that you create a combined unique index on the amount and currency columns.
Define the TCA mapping and then you can persist value objects either directly if you create a repository or by attaching them to aggregate root objects and persisting these.
The price property on your entity should be an integer in the database schema, as extbase will either store a reference to the uid of the VO (if you only refer to one Money object on your entity) and if you wish to store a collection of Money objects, Extbase will store the number of relations between your entity object and the Money VOs.
I have a legacy (old) table with data in a database. Currently, data is put along with ids, so ids are not generated. I'm going to change a source of data. Data from a new source have other ids. These could clash with ids from the legacy table. So I don't want to use them. I'm going to map this data without ids and generate ids with jpa. Will it work if I change my entity for auto-generation and the id column to auto increment? Which options do I have otherwise?
Suppose I have following 4 collections:
1- posts
2- companies
3- groups
4- users
Bellow is my current structure in post:
and their relation is:
A company has an owner and many other members (user collection).
A group has many members (users).
A user has many posts.
A group has many posts that published by one of its members.
A company has many posts that published by its owner or members.
Now i have a problem on storing relation of users, company, and group with posts collection.
Bellow is my current structure:
I have decided to have a field postable inside my post document, and has a type field that will be 'user', or 'group', or 'company', and two other fields name, and id that will be company/group id and company/group name in cases that post is belonged to company or group but not user means type="group" || type="company".
Now how i can handle this to map id as FK of group and company collection (one field FK of two collection) ?
Is it the right structure ?
What you have here is a polymorphic association. In relational databases, it is commonly implemented with two fields, postable_id and postable_type. The type column defines which table to query and id column determines the record.
You can do the same in mongodb (in fact, that is what you came up with, minus the naming convention). But mongodb has a special field type precisely for this type of situations: DBRef. Basically, it's an upgraded id field. It carries not only the id, but also collection name (and database name).
how i can handle this to map id as FK of group and company collection (one field FK of two collection)?
Considering that mongodb doesn't have joins and you have to load all references manually, I don't see how this is any different from a regular FK field. Just the collection name is stored in the type field now, instead of being hardcoded.
I'm building a web application in yesod with mongodb.
I'm tryign to create a model called Message:
Message
_id Text
threadKey Text
body Text
But I can't seem to access the _id field this way, the message_id function doesn't get created, unlike messageThreadKey and messageBody.
How can I access the _id field of mongo objects from yesod/persistent-mongoDB?
In persistent the id (in both the SQL version and the Mongo version) is special and not actually part of the model record. The combination of a Id and a Model Record is called an Entity.
I would reread the persistent chapter of the Yesod book under the Manipulation section, Insert subsection.
http://www.yesodweb.com/book/persistent
I am using Breeze (http://www.breezejs.com/) and to use the functionality I want it requires mapping to a complete entity and all of its fields. I have a "Person" entity, but it includes a Social Security Number field. I want to keep this SSN# field private so I would like to create an entity named SubSetPerson that is updateable, has navigation properties and only contains the columns I want (e.g. ID, FirstName, LastName, myNavigationProperty) and does not contain the SSN#. I am using database/model first. Is this possible?
If you are using database first, then you could create a view for that table which only selects the columns you want. Then update the EF model browser to include that view.
Try using a Master-Detail type structure for your person. The master table would contain the person's public information; ie name, birthdate, etc... The detail table would contain only the more sensitive information (SSN, etc...). Then depending on your needs you can load the detail or not.