Welcome Guest, Not a member yet? Register   Sign In
Datamapper and ID field
#3

[eluser]gte451f[/eluser]
[quote author="WanWizard" date="1335508827"]You need the primary key to uniquely identify a record. In your example, there is no way to do that, so how are you going to delete or modify a single employee record?[/quote]

It may not have been clear from the example, but the Employee->user_id is taken from User->id. It is intended as a unique Foreign Key. Therefore, the employee->user_id can and would be unique under such an arrangement.

[quote author="WanWizard" date="1335508827"]
You may think that you have defined a one-to-one (which by the way isn't a relationship that exists in Datamapper),
[/quote]
I'm confused...here is a One-To-One in the user docs.
http://datamapper.wanwizard.eu/pages/relationtypes.html

Perhaps we are talking about different things?

[quote author="WanWizard" date="1335508827"]
... but you can easily have multiple employee records with the same user_id (for example someone that works part-time for two departments?).
[/quote]

Of course it is *possible* to have multiple employee records but misses the point of the example. This example is intended to illustrate a common relationship where a "Child" table bases its existence on a "Parent" table. In the relationship, the child takes a Foreign Key from the parent that is unique to the child table.



[quote author="WanWizard" date="1335508827"]
You will have to make this a one-to-one in your application code, by making sure you don't create one with a given user_id while another one exists. Datamapper is not aware of that.

For this to work, you will need a "belongs_to" type of relation, which doesn't exist in Datamapper. It will also need complete new logic for interacting with tables, making the library even more complex.[/quote]

Understood. I'm not really looking to add a belongs to type relationships because it would be difficult!

Rather, I'd like to drop the requirement that every datamaper model require a table to have a Auto Increment PK called ID. In some examples the child table doesn't need this type of field since it takes its parent table Primary Key.

Specifically, could we optionally drop the requirement that the PK name = "Id" and could be drop the Auto Increment part as well?


Messages In This Thread
Datamapper and ID field - by El Forum - 04-26-2012, 04:02 PM
Datamapper and ID field - by El Forum - 04-26-2012, 11:40 PM
Datamapper and ID field - by El Forum - 05-01-2012, 12:21 PM
Datamapper and ID field - by El Forum - 05-01-2012, 11:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB