Welcome Guest, Not a member yet? Register   Sign In
Datamapper - many to many relationship - multiple of these but unique by 'date'
#1

[eluser]drakeonfire[/eluser]
Hello,

Hopefully I'll be able to explain this clearly and what I am trying to achieve, and what I currently have.

There are three tables: tasks, users, tasks_users

A user can have many tasks, and a task can have many users.

In the table "tasks_users" there are 4 columns: id, task_id, user_id, item_date

The problem I am facing is that, if I am user 1 for example, and I am associated with tasks 2,3,4. These can have any item_date they want.

As a task may be done multiple times during a week for example (picture a user dragging tasks onto a calender, the day they are droppd on is what defines the item_date). A user can not do the same task twice on a day (which I have already managed to cover).

However - this should not stop a user doing a task multiple times over several days, e.g. once on day 1, once on day 4.

The problem is, when I try and save this new relationship, it would overwrite the day 1 and just replace the date with the date of day 4.

Essentially the relationship should be able to have multiple rows of the same user_id and task_id, as long as they have different dates.

Any ideas on how I can solve this? I have looked through the user guide at advanced relationships and what-not but can not seem to find anything regarding my issue. Any ideas :-)?

Thank you,
Drake.
#2

[eluser]WanWizard[/eluser]
You can't solve it this way. At any given time, you can only have one relation between two records.

What you can do is break the relation up, and make a model for your current relationship table, which will then have a has_one to both tasks and users. And you can create as many records as you want, relating to the same task and user.
#3

[eluser]drakeonfire[/eluser]
Ah, I was hoping I'd be able to do it without having to resort to that, but thanks for the quick reply. :-)




Theme © iAndrew 2016 - Forum software by © MyBB