Closed artemrizhov closed 8 years ago
The relations are a bit different. 1:1 is referring to employee:manager, and 1:N is referring to project:locations. In Backbone Associations when you want to create a one to one relation, you create a Backbone.One relation on a single model which relates to a another model. If you then decide to create the opposite relation on that model, you have created a cyclical relationship. Locations don't have a single project, a project has many locations, and so if you add locations to a project, the collection of locations on that project are updated, which create the Backbone.Many relationship. Locations do not have many projects.
Backbone Associations was created with one to one and one to many in mind. You can create many to many relations, but they won't be very efficient, and you will most likely be better off coming up with your own solution.
So to answer your question, the naming is not confusing it is describing its behavior. Why do you feel that example represents a many to many relationship?
Well, maybe the examples is not clear enough for me. Project and locations make as much sense as "foo" and "bar". I don't understand why project has many locations, why location can't have many project, and how many employes the manager has. Maybe the examples would be much more clear if you use City, Country and ZipCode, i.e. something that all of us can understand without doubts.
What is the relation between employe and manager in your examples?
@artemrizhov : Please look at the ER diagram provided with the help for the relationships http://dhruvaray.github.io/backbone-associations/docs/img/cd_example.png
@dhruvaray Thanks for the diagram. It is helpful. If so, I have to say that imo the example provided is very confusing. I'm still in doubt.
I think you are reading the diagram wrong...
Hi! I'm looking for a Backbone plugin that adds a method to work with relations. And I was surprised and confused when reading your project documentation. Could you please help me to understand how this works?
The project home page says:
You provide two types of relations:
Backbone.One
andBackbone.Many
, so I assume they are 1:1 and 1:N respectively. Let's see the examples:This probably means each employee is associated with one manager. This is a kind of foreign key in relational database, and corresponds to one-to-many relation in the relational model, because each manager is associated with many employees. Is this what you mean?
Let's see the next example:
This probably means each project is associated with many locations. I'm not sure why your project has many locations and what use case you demonstrate here, but this is probably what you mean because the key is
locations
, notlocation
, and you also do this:This probably means we can add more locations to the project. While we also probably can add same locations to another projects. If this is true then this means each project can be associated with many locations, and each locations can be associated with many projects. This is called many-to-many in the relational model.
If I understand correctly, Backbone.One is one-to-many (or many-to-one to be more correct) relation, and Backbone.Many is many-to-many relation. This is usually specified as 1:N and N:M.
Am I right or wrong regarding to the meaning of your examples? If I'm right then don't you think your naming is a bit confusing? Why not to use traditional notation?