Welcome Guest, Not a member yet? Register   Sign In
[Resolved] DataMapper Advanced Relationship won't save but will delete?
#1

[eluser]drakeonfire[/eluser]
Hi guys,

I found the problem, I was using 'other_field' instead of using 'join_other_as', it's working now.

I feel so stupid :-(.

Thank you.


Hello,

I'm having problems trying to save an advanced relationship (e.g. using non-normal field names in the table).

I have a table called "users", this has a many to many relationship with a table called "events".

A user may be a "creator" or a "attendee" of an event, and thus the relationship from the events model looks like:
Code:
var $has_many = array(
'creator' => array(
  'class' => 'user',
  'other_field' => 'creator'
),
'attendee' => array(
  'class' => 'user',
  'other_field' => 'attendee'
)
);

The relationship from the "user" model is just simply:
Code:
var $has_many = array('event');

The issue I'm having is when I'm trying to save the relationship, I load the event and then try and save it via:
Code:
$event->save_creator($user);

This returns TRUE as if it had saved correctly, but in the database no relationship has been created.

When I try and delete a relationship after manually creating it in the database, using the code:
Code:
$event->delete_creator($user);
The relationship is deleted OK.

Any ideas on why I can't get this relationship to save? I've tried saving it as a attendee as well but that doesn't work either.

The join table is: events_users and looks like:
id, event_id, creator_id, attendee_id


Thanks.
#2

[eluser]drakeonfire[/eluser]
Hi guys,

I found the problem, I was using 'other_field' instead of using 'join_other_as', it's working now.

I feel so stupid :-(.

Thank you.

#3

[eluser]WanWizard[/eluser]
I like problems that solve themselfs before I see them... Smile
#4

[eluser]drakeonfire[/eluser]
Haha - if only the problem had solved itself before I saw it! Then this thread would not of been created!




Theme © iAndrew 2016 - Forum software by © MyBB