Quite surprised that I couldn't find a similar question around here.
I'm looking for a way to create relationships (father / sister / wife etc.) between people, preferably within the vCard. I could quite easily create a db that holds the relationships, but then the app will not adhere to a standard or recommendation.
Does anybody know a relevant standard or recommendation?
The RELATED property does exactly that (see RFC 6350 p.43). Quoting the specs, the purpose of this property is:
To specify a relationship between another entity and the entity
represented by this vCard.
Its value can be either a URI or free-form text. Examples of useful URIs include website addresses, URLs pointing to a vCard, or URNs that reference the UID property of another vCard.
It also has a TYPE parameter, which can optionally be used to define the type of relationship. The list of acceptable values for this parameter can be found in the vCard specs.
RELATED;TYPE=parent:http://example.com/jeb-doe.vcf
RELATED;TYPE=sibling:urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6
RELATED;TYPE=spouse;VALUE=text:Jane Doe
RELATED is supported in vCard version 4.0.
And for vCard 3 you might want to mirror what iOS/OSX do:
item3.X-ABRELATEDNAMES:John Doe
item3.X-ABLabel:_$!<Father>!$_
item4.X-ABRELATEDNAMES:Judy Doe
item4.X-ABLabel:_$!<Sister>!$_
item5.X-ABRELATEDNAMES:Joanna Doe
item5.X-ABLabel:_$!<Mother>!$_
Related
I have a debate with a co-worker whether we should use singular or plural for database table names (the Doctrine annotations). He suggests singular names, but i find it way more logical to have it in plural names and i was wondering if there is any recommendation from Symfony because i couldn’t find any.
Thoughts?
As already mentioned by Alexander Marinov, this is not a Symfony question, Symfony does not have any recommendation for this - this is more of a database design question - and is a duplicate of many questions here on stackoverflow and around the internet as such.
But to give you some ideas, you have several options:
Use singular:
This is most commonly used. If you are concerned that the table name in singular makes no sense think about it this way - the table name represents one record in it, not all of them.
This also makes your code sensible - as already stated by Fabian, you want to create singulars in code.
Use plural:
It might make sense in database, but the entity name and code will be ugly - just think of $car = new Cars();
Use both singular and plural:
Doctrine allows you to specify different table name than entity name using the #Table annotation, but this is not very common practice, again, if you think of the table name as a representation of one record in the table, and not collective name for all records in it, this option does not make much sense.
There is a lot of discussion about this around the internet, look around, get some ideas and then its up to you and your colleague what you agree on.
Some examples:
Table Naming Dilemma: Singular vs. Plural Names
https://medium.com/#fbnlsr/the-table-naming-dilemma-singular-vs-plural-dc260d90aaff
I am modeling an ontology that should be used to represent knowledge about restaurants, their served dishes, prices and cuisines types.
One of the functionalities of this system will be to allow users browsing for places to eat some specific kind of Dishes or to search restaurants that are specialized in some cuisines.
Given that in mind, I have modeled the first version of my ontology, but I question appeared.
To represent the specialty of a Restaurant: (a) should I do it as an Object Property, having a class Cuisine, or (b) just as a data property, i.e. being a simple attribute of the Restaurant Class?
Which are the implications of choosing a or b?
In principle, the purpose of an ontology is to describe knowledge about a certain topic. An ontology should partially answer the question "What is a [NameOfTheConceptYouWantToDefine]?". In OWL, the question is answered by providing categories (OWL classes) and binary relations between objects of the categories (OWL individuals) or between an object and a data value (literals). For instance, ask yourself the question "what is an ingredient?". If your answer is "an ingredient is a finite sequence of unicode characters", then you'll need a datatype property to relate something to an ingredient. If you believe that an ingredient is a date or a number, same.
However, if you think an ingredient is an entity that cannot be digitally encoded in a data structure, then you may need a specific class for it, and object properties to relate things to it.
However, ontologies may also be used as a guide to data structures about the things you describe. Sometimes, it is convenient to use a character string as a description of the thing rather than talk about the thing itself. For instance, one may use a string to describe the ingredients of a recipe. This string should not be confused with the ingredient itself. To make this distinction explicit, you can use datatype properties with a clear name like ex:ingredientDescription.
Now, ask yourself "what is a cuisine?". Is it a string, a number, a date? Do you need to describe further the cuisines or do you just need a string-based cuisine description?
The motto of Semantic Web is “Things, not strings”. This is what makes RDF/RDFS/OWL different from other modelling frameworks.
In OWL 2, object properties might possess different characteristics, while data properties mightn't:
Also, data properties can not be parts of property chains. All these restrictions are due to decidability reasons.
There exist quite a few cuisines, they can have their own attributes (at least, detailed descriptions) and relations, so I'd suggest to use object properties.
I am working with a customer that uses this kind of table name:
mod42_tabname
and for field names:
mod42_fieldname
and for foreign key I can see:
mod32_tab54_field_fk18
Does this pattern have a name?
Are there principles violated here?
Are there some suggestion to push customer to use simple and better to remember names?
In my personal experience, I would not speak of patterns or principles, but of nomenclature conventions combined with best practices; then these conventions are personal or business choices. The important thing is that the conventions adopted are kept within the project.
For example, I prefer to create tables with singular names (as the names od classes in the OOP are singular), while others use plural names.
This is a style guide about elements to name and the main conventions adopted.
Another method used, as in your case, is to group the tables, if the application is organized in independent modules and you do not want to use different databases.
I prefer to use different databases, but if this is not possible, this solution is often used.
As for the use of the prefix also in the name of fields, I find it very redundant because I have information already present in the table name.
As for your client's convention, is it applied to an existing application or is it still being evaluated?
In the first case, I see the change difficult because with time you will find a database with elements named differently.
In the second case, I would look for a less redundant and more speaking convention
I have to design a generic entity that would be able to refer to variated other entities.
In my example, that would be a commentary entity inside a web application. You could post commentaries on to users, classifieds, articles, varieties (botanical ones), and so on.
So that entity would be made like this:
As a matter of fact, the design (kind of) pattern would be this one:
What are the pros and cons of this kind of pattern?
What I see is:
Pros
It decreases the number of entities if the concept is the same (commentaries for example);
You can therefore easily manipulate heterogeneous objects;
You can aggregate these objects easily (e.g. this user's last commentaries in the whole site, presented easily in a same thread);
Cons
This allows you to fall in the ugly (you use it outrageously and your database and source code are ugly);
There is no control in the database, and this one must therefore be done inside the application code.
What are the performances impacts?
Conclusion
Is this kind of pattern suitable for a relational database? How can we do then?
Thank you by advance.
One more con :
This scheme relies on a mapping between values and names for the "entities" referred to by those values. Think of all the fun you'll have resolving issues that in the TEST system, the ORDER entity has number 734 but in production, it has number 256. You can use the entity names themselves as the values of your entity_id stuff, but you will never be able to avoid hardcoding values for them in your programs (or, say, in view definitions) anyway. Thereby defeating whatever advantage it was you thought you could win.
This kind of scheme is a disease mostly suffered by OO programmers. They see structures that are largely similar and they have this instinctive reflex "I must find a way to resue the existing thing for this". Forgetting that database design is not program design.
EDIT
(if it wasn't clear, this means my answer to your question "Is this kind of pattern suitable for a relational database?" is a principled "NO".)
This is the classic Polymorphic Association anti-pattern. There are a number of possible solutions:
1) Exclusive Arcs e.g. for the Commentary entity
Id
User_Id
Classified_Id
Article_Id
Variety_Id
Where User_Id, Classified_Id, Article_Id and Variety_Id are nullable and exactly one must be not null.
2) Reverse the Relationship e.g remove the Target_Entity and Target_Entity_Id from the Commentary entity and create four new entities
User_Commentary
Commentary_Id
User_Id
Classified_Commentary
Commentary_Id
Classified_Id
Article_Commentary
Commentary_Id
Article_Id
Variety_Commentary
Commentary_Id
Variety_Id
Where Commentary_Id is unique and relates to the Id in Commentary.
3) Create a super-type entity for User, Classified, Article and Variety and have the Commentary entity reference the unique attribute of this new entity.
You would need to decide which of these approaches you feel is most appropriate in your specific situation.
Here's three best practices I try to follow when naming tables:
Never name a table with plural (such as "users")
Never name a table using a reserved keyword (such as "user")
Never prefix your table name with "tbl" or some other object type prefix
Keeping all this in mind, how do you recommend naming the table that will hold user identities?
I agree, do not use any reserved words, or quoted or bracketed or escaped forms of reserved words.
Name the User table Person.
You may be interested in this answer and google for the ISO standard 11179 for naming Guidelines
I typically use something like member or account, depending on the application. That said, if you're using modern design tools and principles (e.g., a db abstraction layer or ORM with an object-oriented code base that separates business logic from data access), then table naming becomes fairly irrelevant. Your developers should only ever be accessing the database through a well-defined interface and not by hand-writing SQL that requires them to know the table name. For example, you could name the table account but map access to it via an object named User. Your developers shouldn't be thinking in terms of tables, but in terms of access objects, which aren't going to have the same restrictions on naming:
$user = new User($username);
$user->authenticate($password);
Use a synonym. What word to use depends on what exactly you store in the table, but account strikes me as a good alternative. If you want to use a variation user I'd break the first guideline you mention, not the second or third: users is common enough that the inconsistency is essentially mnemonic.
Do not use reserved words or quoted or escaped words for database table names.
If you really want to do this then you need to escape the names:
quotation marks: "user"
Java + JPA escaping: #Table(name = "\"user\"")
I highly not recommend using plural worlds for database table names like USERS. This is a BAD PRACTICE, against the SQL naming convention. Database table names need to be singular nouns.
I recommend using ACTOR for a database table name to store users details. This name is clear, understandable and enough general. It can be used for companies and individuals as well (not like ex. PERSON, which fit for only person but not companies).
I use CakePHP rules even when I don't use the framework :
Table names are by convention lowercase and pluralized with multi-word table names separated by underscores. For example, a Model name of Ingredient expects the table name ingredients. Model name of EventRegistration would expect a table name of event_registrations.