In your use case it can only be Long and User. But there has to be a type parameter because other people might have a String key and a Request mapper. And the contents of ManyToMany have to be type safe to enforce their consistency with however the user of ManyToMany wants them to use it.So I think what you want is that the compiler should figure out that since you're using it with a KeyedMapper[Long, User], which is ManyToMany's T <: KeyedMapper[K,T], and ManyToMany extends KeyedMapper[K,T] and it has a self type of T, and therefore it would be a compiler error to write anything besides Long and User, therefore you must want to use Long and User and they should be inferred. I could certainly hear that, although I'm not much of a type theorist. So feel free to open an enhancement ticket on Scala's Trac! :) If I understood correctly...
On Thu, Aug 6, 2009 at 12:43 PM, glenn <gl...@exmbly.com> wrote: > > Naftoli, > > As I said at the outset, this is really beyond my expertise. But I > think it's too > broad and maybe, even unnecessary. In my example, K can only be one > type, > Long, and T can only be of type User. Anything else, and the compiler > can't be > guaranteed to catch it, but try running the application and you get > things like > stack overflow errors. > > How you would fix this is beyond me. All you can really do, at this > point, is > make sure to include these kinds of restrictions in the docs. > > Glenn... > > On Aug 6, 9:33 am, Naftoli Gugenheim <naftoli...@gmail.com> wrote: > > It's too broad, or it's too restrictive/unnecessary? I'm confused, you > seem > > to imply both.If it's too broad, tell me why. But if you want to know why > it > > needs the type parameter, it's because it has to use the type parameter > in > > its implentation -- just count how many times its source code uses it! > And > > if you want to know why the compiler can't infer it or be told to infer > > it... that's another issue. > > But if passing a type that creates a conflicting inheritance causes a > > compiler crash, that's not something I can help. :) > > Regards. > > > > On Thu, Aug 6, 2009 at 12:26 PM, glenn <gl...@exmbly.com> wrote: > > > > > Naftoli, > > > > > At the risk of discussing something obviously beyond my pay grade, > > > isn't the real issue Scala traits > > > and the use of parameterized types. The ManyToMany trait is defined > > > as: > > > > > trait ManyToMany[K,T<:KeyedMapper[K, T]].... > > > > > But this isn't really correct,is it, the parameter is too broad, and > > > that leads to a lot of the confusion and results in the need for > > > unnecessary documentation. When you think about it, why all the > > > duplication? Why do I need to > > > write my User entity as: > > > > > class User extends MegaProtoUser[User] with ManyToMany[Long,User] > > > > > when we all know that this would be much cleaner: > > > > > class User extends MegaProtoUser[User] with ManyToMany. > > > > > But traits aren't like interfaces. They have implementation and would > > > need to know something about > > > the parent class they are attached to - and how would you accomplish > > > that (reflection, maybe). This is > > > more a Scala issue than a Lift one, I think. > > > > > Glenn... > > > > > On Aug 5, 8:24 pm, Naftoli Gugenheim <naftoli...@gmail.com> wrote: > > > > Building causes a stack overflow? > > > > So the question is, is it the resident compiler or plain scalac also > > > crashes? Or just the presentation compiler? What do you see in the > error log > > > view or file? > > > > I get compiler crashes very often when doing fancy mapper type > related > > > tricks. > > > > > > ------------------------------------- > > > > > > glenn<gl...@exmbly.com> wrote: > > > > > > Naftoli, > > > > > > Hate to do this to you, but I'm getting the following error using > > > > ManyToMany for Users to Roles: > > > > > > Message: java.lang.RuntimeException: Broken join > > > > scala.Predef$.error(Predef.scala:76) > > > > > net.liftweb.mapper.ManyToMany$MappedManyToMany$$anonfun$children$1$ > > > > $anonfun$apply$1.apply(ManyToMany.scala:54) > > > > > net.liftweb.mapper.ManyToMany$MappedManyToMany$$anonfun$children$1$ > > > > $anonfun$apply$1.apply(ManyToMany.scala:54) > > > > net.liftweb.util.EmptyBox.openOr(Box.scala:372) > > > > > net.liftweb.mapper.ManyToMany$MappedManyToMany$$anonfun$children > > > > $1.apply(ManyToMany.scala:54) > > > > > net.liftweb.mapper.ManyToMany$MappedManyToMany$$anonfun$children > > > > $1.apply(ManyToMany.scala:54) > > > > scala.List.map(List.scala:812) > > > > net.liftweb.mapper.ManyToMany$MappedManyToMany.children > > > > (ManyToMany.scala:54) > > > > net.liftweb.mapper.ManyToMany$MappedManyToMany.elements > > > > (ManyToMany.scala:96) > > > > scala.Seq$class.flatMap(Seq.scala:293) > > > > net.liftweb.mapper.ManyToMany$MappedManyToMany.flatMap > > > > (ManyToMany.scala:44) > > > > > > def edit(ns: NodeSeq): NodeSeq = { > > > > val theUser = view.entity > > > > val addRole = TheBindParam("insert", view.snippet.link("edit", () > > > > => theUser.roles += new Role, Text(S?("Add Role")))) > > > > > > bind("user", ns, > > > > "firstname" -> text(theUser.firstName.is, theUser.firstName > > > > (_), ("size","20")), > > > > "lastname" -> text(theUser.lastName.is,theUser.lastName(_), > > > > ("size", "30")), > > > > "roles" -> theUser.roles.flatMap{role => > > > > bind("role", ns, > > > > "name" -> role.name.toForm, > > > > "remove" -> SHtml.submit(S?("Remove"), ()=> > > > > theUser.roles -= role) > > > > ) > > > > }, > > > > addRole, > > > > "submit" -> SHtml.submit(S?("Save"), ()=>view.save) > > > > ) > > > > } > > > > > > The offending code seems to be the line: "roles" -> > > > > theUser.roles.flatMap{.... > > > > in the above bind method when I click on the addRole link. > > > > > > Here's my User class: > > > > > > class User extends MegaProtoUser[User] with ManyToMany[Long,User]{ > > > > def getSingleton = User // what's the "meta" server > > > > > > object roles > > > > extends MappedManyToMany(UserRole, UserRole.user, UserRole.role, > > > > Role) > > > > > > } > > > > > > What am I doing wrong? You can see how difficult it is to slog > through > > > > this code, let alone just > > > > trying to explain the problem so I can get help. > > > > > > On Aug 5, 9:57 am, Naftoli Gugenheim <naftoli...@gmail.com> wrote: > > > > > > > I'll try. > > > > > By the way, as per my correction, you can implement list the > regular > > > way without ModelView, and just use ModelSnippet's load function in > your > > > edit link or button, passing it the User instance. > > > > > > > ------------------------------------- > > > > > > > glenn<gl...@exmbly.com> wrote: > > > > > > > Naftoli, > > > > > > > I fixed my code per your comments and now I can edit and remove > users > > > > > from a list, as long as I populate the list with > > > > > ModelView instances, as you said. As for the docs, this step was > not > > > > > clear to me at all. I just assumed that the list was > > > > > just populated with User entities and the view in the ModelSnippet > was > > > > > instantiated with the selected User on each request. > > > > > > > It sounds like your plate is pretty full, so I won't expect much, > but > > > > > sometime soon, could you provide an example, or improved > > > > > docs, for using TableEditor and its related ItemsList trait. > > > > > > > Thanks for all. > > > > > > > Glenn... > > > > > > > On Aug 5, 9:18 am, Naftoli Gugenheim <naftoli...@gmail.com> wrote: > > > > > > > > Correction: ModelSnippet.load takes the actual Mapper instance, > not > > > the ModelView wrapper. > > > > > > > > ------------------------------------- > > > > > > > > Naftoli Gugenheim<naftoli...@gmail.com> wrote: > > > > > > > > To answer your immediate question, the listing should not refer > to > > > the snippet's view but new ModelView instances for each entity. Then > > > editAction is shorthand for the snippet's link method with a callback > to > > > call load on the ModelView. To set the snippet's view's entity, either > call > > > load on the snippet with the other ModelView, or call load on the other > > > ModelView (or just set its entity directly). > > > > > > As far as documentation, please tell me what scaladocs need what > > > clarification. Thanks. > > > > > > > > ------------------------------------- > > > > > > > > glenn<gl...@exmbly.com> wrote: > > > > > > > > Naftoli, > > > > > > > > Functional programming systems are notoriously difficult to > document. > > > > > > The only way to really know what's going on is to meticulously > trace > > > > > > through the source. But that requires > > > > > > time-consuming trial and error coding. So, without clear examples > > > > > > demonstrating exactly what you have in mind, I and others in the > same > > > > > > boat, could spend days and still not > > > > > > get it right. > > > > > > > > For example, I tried this: > > > > > > > > var theUser:User = null > > > > > > val view = new ModelView(theUser, this) > > > > > > > > def list(ns: NodeSeq): NodeSeq = User.currentUser.map({user => > > > > > > User.findAll.flatMap({u => > > > > > > bind("user", chooseTemplate("user", "entry", ns), > > > > > > "firstname" -> Text(u.firstName.is), > > > > > > "lastname" -> Text(u.lastName.is), > > > > > > "email" -> Text(u.email.is), > > > > > > "roles" -> > u.roles.map(_.name.toString).mkString(", > > > > > > "), > > > > > > view.editAction, > > > > > > view.removeAction > > > > > > ) > > > > > > }) > > > > > > }) openOr Text("You're not logged in") > > > > > > > > and, I get a null value exception when I try to remove a user in > the > > > > > > list. Simply using > > > > > > val view = new ModelView(new User, this), doesn't work either, > > > > > > although I don't get an > > > > > > exception. Now, where should I be calling load in all of this? > > > > > > > > Glenn... > > > > > > > > On Aug 3, 6:22 pm, Naftoli Gugenheim <naftoli...@gmail.com> > wrote: > > > > > > > > > Your snippet should extend ModelSnippet (which extends > > > StatefulSnippet). > > > > > > > Then write: > > > > > > > val view = new ModelView(new User, this) {} > > > > > > > Calling load on another ModelView that references the snippet > will > > > load its entity into that view val. It has a number of methods of > possible > > > interest, like save which checks validity. > > > > > > > Also see Util. > > > > > > > Are you seeing the scaladocs? > > > > > > > > > ------------------------------------- > > > > > > > > > glenn<gl...@exmbly.com> wrote: > > > > > > > > > Just to add to what I just wrote, I don't see how your > ModelView > > > can > > > > > > > be applied to > > > > > > > User, which already extends a class, MegaProtoUser. Maybe I'm > not > > > > > > > comprehending this correctly. > > > > > > > > > Glenn... > > > > > > > > > On Aug 3, 3:48 pm, glenn <gl...@exmbly.com> wrote: > > > > > > > > > > Naftoli, > > > > > > > > > > Liked your OneToMany article, but not sure how the new > > > > > > > > ModelView and ModelSnippet code can be applied to ManyToMany. > > > > > > > > Can you provide a sample? > > > > > > > > > > Glenn... > > > > > > > > > > On Aug 2, 1:21 pm, Naftoli Gugenheim <naftoli...@gmail.com> > > > wrote: > > > > > > > > > > > I put an article on the wiki about OneToMany -- > > >http://wiki.github.com/dpp/liftweb/how-to-work-with-one-to-many-relat. > .. > > > > > > > > > . > > > > > > > > > > > On Sun, Aug 2, 2009 at 11:20 AM, Naftoli Gugenheim < > > > naftoli...@gmail.com>wrote: > > > > > > > > > > > > Glad to hear. Also see mapper.view.ItemsList (anyone have > a > > > better name?), > > > > > > > > > > which is used byTableEditor. It's a similar idea without > > > relationships. > > > > ... > > > > read more ยป > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Lift" group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~----------~----~----~----~------~----~------~--~---