Page 1 of 1

Multi Insert

PostPosted: Thu May 03, 2012 12:22 pm
by jmboettger
Hi there,

i'm still trying to insert more than one row at once in a join table (user user2course course). For example adding many users to one Course. If i try to solve it with a sql query selecting
Code: Select all
__sql__ ="SELECT * FROM user2cource WHERE courseID = '$courseID'"
it shows a advmultiselect list but justs adds one of the selected records.

Any Ideas?

Thanks and best Regards

Jakob

Re: Multi Insert

PostPosted: Fri May 04, 2012 2:57 am
by camt
Hi Jakob, have you had a look at the grid widget at all?
This should do what you want - add multiple users to a relationship in one form
http://xataface.com/wiki/grid

Re: Multi Insert

PostPosted: Fri May 04, 2012 11:40 am
by jmboettger
Thanks that looks Brilliant. Indeed i did't look at this widget. Now i just have the Problem, that it does not add existing records, instead it creates new ones.
I got three tables

First one
User
columns
UserID
Name
Street

Second one
User2Course
columns
UserID
CourseID

Third one
Course
columns
CourseID
Title
Date

These Three Tables are referenced with a M:N relationship.

Now i implemented the Grid Widget at the Course Table with the Relationship
Code: Select all
[Teilnehmer]
User.UserID = User2Course.UserID
User2Course.CourseID = "$CourseID"


If i try adding users to Courses it always creates new ones instead of adding existing records.

Any Ideas?

Thanks

and Best Regards Jakob

Re: Multi Insert

PostPosted: Mon May 07, 2012 11:41 am
by shannah
It is sometimes easier to create a "dummy" relationship that is one-to-many that goes from the source table to the join table only (doesn't go all the way to the destination table). Use this relationship with the grid widget and use the lookup widget on the id column in the join table so that each row of the grid widget will just have a lookup widget, whose widget:table directive is the destination table of the m:n relationship.

Since this is a dummy relationship, you will want to hide it from the relationship tabs:
Code: Select all
action:condition="false"


-Steve