|
Hi, my problem is this, i have 3 domain classes:
Risk { String name static belongsTo = [owner:Person] static hasMany = [comments:Comment] } Issue { String name static belongsTo = [owner:Person] static hasMany = [comments:Comment] } Comment { String description Date dateCreated static belongsTo = [Issue,Risk] static hasMany = [issues:Issue,risks:Risk] } Person has many risk and issues...and a risk and issues can have many comments.. so far so good... I wanted to get the comments for an specific risk or issue... and i wanted it sorted by dateCreated so i added to the Risk domain: static mapping = { comments sort: "dateCreated", order:"desc" } but, when I do: def risk = Risk.get(params.id) risk.comments.each{ ... ... } I'm a getting the error: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'comments0_.date_created' in 'order clause'.. setting logging sql on, the query is: select comments0_.risk_id as risk2_0_, comments0_.comment_id as comment1_0_ from risk_comments comments0_ where comments0_.risk_id=? order by comments0_.date_created desc which I do understand the problem in terms of sql, the column date_create doesn't exist in that table...i saw that grails created for my two tables, risk_comments, and issue_comments, and both tables only have the ids for risk/issue and comment...i don't know what should i do (and this is might be for my ignorance in hibernate/grails...) .. change my design? am i missing something here?...my mapping part it's not ok?... there is another/easiest way? I hope i was able to explain my self.. Any suggestions or comments will be appreciated. Sinceraly: a Grails newbie :) |
|
Anyone?? :/
|
|
I think you should add "sort" to the Comment class:
static mapping = { sort dateCreated:"desc" } http://grails.org/doc/latest/ref/Database%20Mapping/sort.html chamukin32 wrote: > Anyone?? :/ --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
From the docs, your code should work:
class Airport { static hasMany = [flights:Flight] static mapping = { flights sort:'number', order:'desc' } } http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20(GORM).html#5.5.3%20Default%20Sort%20Order Daniel Henrique Alves Lima wrote: > I think you should add "sort" to the Comment class: > (...) --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Thanks for your replays Daniel...
I added that line as you suggested me, but the error it's kinda the same: Hibernate: select comments0_.risk_id as risk1_0_, comments0_.comment_id as comment2_0_ from risk_comments comments0_ where comments0_.risk_id=? order by comments0_.date_created desc util.JDBCExceptionReporter Unknown column 'comments0_.date_created' in 'order clause' This would work if i'd try to get the comments like.. Comments.list() or findAllBy I think......but I want the comments associated to an specific Issue or Risk.. so i'm getting first the issue or risk: def issue = Issue.get(params.id) then i just get the comments like: issue.comments (Issue and Risk has many comments)... should I re-write my design? or there is another way to obtain the comments ordered for an specific issue or comment?? I must be doing something wrong... I thinks it is the way i'm trying to obtaing the comments...my domain class Comment looks like this: class Comment { String comment String createdBy Date dateCreated Date lastUpdated static belongsTo = [Issue,Risk] static hasMany = [issues:Issue,risks:Risk] static constraints = { comment(nullable:false,maxSize:255) } static mapping = { sort dateCreated:"desc" } } what do you think? Thx |
|
If in my domain class Comment i change the lines:
static belongsTo = [risk:Risk,issue:Issue] static hasMany = [issues:Issue,risks:Risk] for: static belongsTo = [risk:Risk] //static hasMany = [issues:Issue,risks:Risk] the sort works well, but only for risk... so, I think i will rewrite my design... thx |
|
In reply to this post by chamukin32
It seems to me that this question has not really been answered.
It's also just the type of question that frustrates newbies so that they give up. If one tries to do a simple sort and cannot even get that done, they go away. I remember going through Grails in Action I think and they have some list that in the book sorts but when I tried it it came unordered. So after a week of screwing with it, I just gave up on Grails for another few months. ********* Could one of you real experts help this person? And then with what we learn can we do something that helps other not hit it again (maybe a beginners FAQ; maybe I'll even compile it) My guesses on bad sorts: I've seen the sort in the static mapping not work because it returns a Set which has no ordering. I've seen people suggesting ways to make it return a SortedSet (too hard for a newbie) or List. Could that work here? He has dateCreated, lastUpdated as explicit domain fields. Isn't that field or something like that already created by default? Does this create some sort of conflict? ********** Videos are great to pull people in but it's this kind of stuff that pushes people away. On Feb 7, 2011, at 7:43 PM, chamukin32 wrote: > > Thanks for your replays Daniel... > > I added that line as you suggested me, but the error it's kinda the same: > > Hibernate: > select > comments0_.risk_id as risk1_0_, > comments0_.comment_id as comment2_0_ > from > risk_comments comments0_ > where > comments0_.risk_id=? > order by > comments0_.date_created desc > util.JDBCExceptionReporter Unknown column 'comments0_.date_created' in > 'order clause' > > This would work if i'd try to get the comments like.. Comments.list() or > findAllBy I think......but I want the comments associated to an specific > Issue or Risk.. so i'm getting first the issue or risk: > > def issue = Issue.get(params.id) > > then i just get the comments like: issue.comments (Issue and Risk has many > comments)... should I re-write my design? or there is another way to obtain > the comments ordered for an specific issue or comment?? > > I must be doing something wrong... I thinks it is the way i'm trying to > obtaing the comments...my domain class Comment looks like this: > > class Comment { > > String comment > String createdBy > Date dateCreated > Date lastUpdated > > static belongsTo = [Issue,Risk] > static hasMany = [issues:Issue,risks:Risk] > > static constraints = { > comment(nullable:false,maxSize:255) > } > > static mapping = { > sort dateCreated:"desc" > } > } > > what do you think? > > Thx > -- > View this message in context: http://grails.1312388.n4.nabble.com/Sort-not-working-tp3258369p3265485.html > Sent from the Grails - user mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
I don't use GORM at all when doing many to many. Like I mentioned in previous posts, I prefer Burt's method. That is why I didn't bother to reply to this thread. Maybe it has been answered before in other threads.
On Tue, Feb 8, 2011 at 8:30 AM, Scott Eisenberg <[hidden email]> wrote: It seems to me that this question has not really been answered. |
|
So, we should collect this in a wiki. A FAQ would be great.
Like e.g. the blob issue people sorted out for me has come up again a couple of times since. Cheers, Wolfgang On Tue, Feb 8, 2011 at 4:09 PM, Roberto Guerra <[hidden email]> wrote: I don't use GORM at all when doing many to many. Like I mentioned in previous posts, I prefer Burt's method. That is why I didn't bother to reply to this thread. Maybe it has been answered before in other threads. |
|
In reply to this post by Roberto Guerra
I saw your comment. If many-to-many does not work well as described in the doc, the doc should be changed to use Burt's logic.
I think Burt and Graeme should have a pow-wow and decide what the official recommendation should be on associations. It does no good for a newbie to have doc say one thing and everyone else point to another document as to what one should really do. I know Burt comments on the fact that the doc'ed solution works well with small data sets but does not scale and perhaps this needs to be mentioned in the docs. But still we violate the principle of least surprise here. Perhaps we shouldn't train people (via the books and the docs) on the unscalable solution and recommend only Burt's scalable one. My preference personally is the the GORM code be re-looked at to make the current documented solution is the one that scales. Maybe something like looking at the size of the associated data and intelligently doing different things if that data set is small or large. Parameters could be in the config file for where that line separates? PS If you don't make data sorting and table joins easy and perhaps better PREDICTABLE, newbies WILL give up on this framework. On Feb 8, 2011, at 10:09 AM, Roberto Guerra wrote: I don't use GORM at all when doing many to many. Like I mentioned in previous posts, I prefer Burt's method. That is why I didn't bother to reply to this thread. Maybe it has been answered before in other threads. |
|
In reply to this post by Müller, Wolfgang
If I see solutions to stuff, I'll start writing them down.
Send an nabble link to the blob issue you reference. In the future, perhaps answers should have "INCLUDE IN FAQ" in it which will clue me to add it. PS If I really understood the answer to the Sort / Burt Gotchas stuff, I'd include them but they're still hazy to me. On Feb 8, 2011, at 10:12 AM, Müller, Wolfgang wrote: So, we should collect this in a wiki. A FAQ would be great. |
|
In reply to this post by chamukin32
> static mapping = {
> comments sort: "dateCreated", order:"desc" > } This mapping simply doesn't seem to be working properly with many to many relationships: http://jira.codehaus.org/browse/GRAILS-4089 This should probably be made clear in the docs. A suitable workaround is tough to come up with too. I suspect if you need this behaviour, it's better to manage the many-to-many relationship yourself, as described here: http://mrpaulwoods.wordpress.com/2011/02/07/implementing-burt-beckwiths-gorm-performance-no-collections/ Peter -- Peter Ledbrook Grails Advocate SpringSource - A Division of VMware --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by Scott6666
I think in general a wiki is a great thing to accompany a mailing list, because the same questions often come up repeatedly and you can just say it perfectly once and for all in the wiki.
For example, think of the great entry we could have about IDEs :-).
John
|
|
+1 to John. It is about time for a wiki :D.
On Tue, Feb 8, 2011 at 9:47 AM, John Fletcher <[hidden email]> wrote:
|
|
In reply to this post by Scott6666
> I saw your comment. If many-to-many does not work well as described in the
> doc, the doc should be changed to use Burt's logic. I think it's pretty straightforward to use the collections. I guess this will always be a topic of debate: should we promote the efficient approach over the easier to use one? Of course, in this case the 'easier to use' doesn't really apply, but note that's because of a bug. If you don't need the sort mapping for a many-to-many relationship, then the current setup is fine. Perhaps things could be improved, for example by using batch fetching for collections by default. There is also the question of deleting collection items - perhaps we can improve that area too. Don't forget, manually managing collection properties is a fair bit of extra work. Peter -- Peter Ledbrook Grails Advocate SpringSource - A Division of VMware --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Administrator
|
In reply to this post by Scott6666
On Tue, Feb 8, 2011 at 4:19 PM, Scott Eisenberg <[hidden email]> wrote:
> I saw your comment. If many-to-many does not work well as described in the > doc, the doc should be changed to use Burt's logic. > I think Burt and Graeme should have a pow-wow and decide what the official > recommendation should be on associations. It does no good for a newbie to > have doc say one thing and everyone else point to another document as to > what one should really do. > I know Burt comments on the fact that the doc'ed solution works well with > small data sets but does not scale and perhaps this needs to be mentioned in > the docs. But still we violate the principle of least surprise here. > Perhaps we shouldn't train people (via the books and the docs) on the > unscalable solution and recommend only Burt's scalable one. Personally I think saying the default way is unscalable is overstating things. You need to know the disadvantages though one of the major ones being you have to load the entire collection to add an entry. This can be problematic, but it depends on the use case. Obviously if you navigate from object A to object B via a collection and there are millions of Bs the performance is going to suck. If there are only a few Bs then maybe this is ok. However you could still maintain the collection and update only the inverse side (if its bidirectional). You could then use batch fetching to make the performance of iteration better. It really depends. For many applications there are only a few Bs. Take users and roles. A user normally only has a few roles not millions for this use case performance can be completely acceptable. Changing the documentation for this use case would make no sense. I would agree that maybe we should elaborate a little and cover the fact that for larger association types you should use Burt's technique, but that is an expansion of the documentation, not a change. Cheers > My preference personally is the the GORM code be re-looked at to make the > current documented solution is the one that scales. Maybe something like > looking at the size of the associated data and intelligently doing different > things if that data set is small or large. Parameters could be in the > config file for where that line separates? > PS If you don't make data sorting and table joins easy and perhaps better > PREDICTABLE, newbies WILL give up on this framework. > On Feb 8, 2011, at 10:09 AM, Roberto Guerra wrote: > > I don't use GORM at all when doing many to many. Like I mentioned in > previous posts, I prefer Burt's method. That is why I didn't bother to reply > to this thread. Maybe it has been answered before in other threads. > > On Tue, Feb 8, 2011 at 8:30 AM, Scott Eisenberg <[hidden email]> > wrote: >> >> It seems to me that this question has not really been answered. >> >> It's also just the type of question that frustrates newbies so that they >> give up. If one tries to do a simple sort and cannot even get that done, >> they go away. I remember going through Grails in Action I think and they >> have some list that in the book sorts but when I tried it it came unordered. >> So after a week of screwing with it, I just gave up on Grails for another >> few months. >> >> ********* Could one of you real experts help this person? And then with >> what we learn can we do something that helps other not hit it again (maybe a >> beginners FAQ; maybe I'll even compile it) >> >> >> My guesses on bad sorts: >> >> I've seen the sort in the static mapping not work because it returns a Set >> which has no ordering. I've seen people suggesting ways to make it return a >> SortedSet (too hard for a newbie) or List. Could that work here? >> >> He has dateCreated, lastUpdated as explicit domain fields. Isn't that >> field or something like that already created by default? Does this create >> some sort of conflict? >> >> ********** >> Videos are great to pull people in but it's this kind of stuff that pushes >> people away. >> >> >> >> On Feb 7, 2011, at 7:43 PM, chamukin32 wrote: >> >> > >> > Thanks for your replays Daniel... >> > >> > I added that line as you suggested me, but the error it's kinda the >> > same: >> > >> > Hibernate: >> > select >> > comments0_.risk_id as risk1_0_, >> > comments0_.comment_id as comment2_0_ >> > from >> > risk_comments comments0_ >> > where >> > comments0_.risk_id=? >> > order by >> > comments0_.date_created desc >> > util.JDBCExceptionReporter Unknown column 'comments0_.date_created' in >> > 'order clause' >> > >> > This would work if i'd try to get the comments like.. Comments.list() or >> > findAllBy I think......but I want the comments associated to an specific >> > Issue or Risk.. so i'm getting first the issue or risk: >> > >> > def issue = Issue.get(params.id) >> > >> > then i just get the comments like: issue.comments (Issue and Risk has >> > many >> > comments)... should I re-write my design? or there is another way to >> > obtain >> > the comments ordered for an specific issue or comment?? >> > >> > I must be doing something wrong... I thinks it is the way i'm trying to >> > obtaing the comments...my domain class Comment looks like this: >> > >> > class Comment { >> > >> > String comment >> > String createdBy >> > Date dateCreated >> > Date lastUpdated >> > >> > static belongsTo = [Issue,Risk] >> > static hasMany = [issues:Issue,risks:Risk] >> > >> > static constraints = { >> > comment(nullable:false,maxSize:255) >> > } >> > >> > static mapping = { >> > sort dateCreated:"desc" >> > } >> > } >> > >> > what do you think? >> > >> > Thx >> > -- >> > View this message in context: >> > http://grails.1312388.n4.nabble.com/Sort-not-working-tp3258369p3265485.html >> > Sent from the Grails - user mailing list archive at Nabble.com. >> > >> > --------------------------------------------------------------------- >> > To unsubscribe from this list, please visit: >> > >> > http://xircles.codehaus.org/manage_email >> > >> > >> >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > > -- Graeme Rocher Grails Project Lead SpringSource - A Division of VMware http://www.springsource.com --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Is there a design where choosing between the two is done automagically and transparent to the user?
I'd say perhaps try to create a plug-in but this seems to a bit fundamental than that. On Feb 8, 2011, at 11:01 AM, Graeme Rocher wrote: > On Tue, Feb 8, 2011 at 4:19 PM, Scott Eisenberg <[hidden email]> wrote: >> I saw your comment. If many-to-many does not work well as described in the >> doc, the doc should be changed to use Burt's logic. >> I think Burt and Graeme should have a pow-wow and decide what the official >> recommendation should be on associations. It does no good for a newbie to >> have doc say one thing and everyone else point to another document as to >> what one should really do. >> I know Burt comments on the fact that the doc'ed solution works well with >> small data sets but does not scale and perhaps this needs to be mentioned in >> the docs. But still we violate the principle of least surprise here. >> Perhaps we shouldn't train people (via the books and the docs) on the >> unscalable solution and recommend only Burt's scalable one. > > Personally I think saying the default way is unscalable is overstating > things. You need to know the disadvantages though one of the major > ones being you have to load the entire collection to add an entry. > > This can be problematic, but it depends on the use case. Obviously if > you navigate from object A to object B via a collection and there are > millions of Bs the performance is going to suck. If there are only a > few Bs then maybe this is ok. However you could still maintain the > collection and update only the inverse side (if its bidirectional). > > You could then use batch fetching to make the performance of iteration > better. It really depends. > > For many applications there are only a few Bs. Take users and roles. A > user normally only has a few roles not millions for this use case > performance can be completely acceptable. Changing the documentation > for this use case would make no sense. > > I would agree that maybe we should elaborate a little and cover the > fact that for larger association types you should use Burt's > technique, but that is an expansion of the documentation, not a > change. > > Cheers > > >> My preference personally is the the GORM code be re-looked at to make the >> current documented solution is the one that scales. Maybe something like >> looking at the size of the associated data and intelligently doing different >> things if that data set is small or large. Parameters could be in the >> config file for where that line separates? >> PS If you don't make data sorting and table joins easy and perhaps better >> PREDICTABLE, newbies WILL give up on this framework. >> On Feb 8, 2011, at 10:09 AM, Roberto Guerra wrote: >> >> I don't use GORM at all when doing many to many. Like I mentioned in >> previous posts, I prefer Burt's method. That is why I didn't bother to reply >> to this thread. Maybe it has been answered before in other threads. >> >> On Tue, Feb 8, 2011 at 8:30 AM, Scott Eisenberg <[hidden email]> >> wrote: >>> >>> It seems to me that this question has not really been answered. >>> >>> It's also just the type of question that frustrates newbies so that they >>> give up. If one tries to do a simple sort and cannot even get that done, >>> they go away. I remember going through Grails in Action I think and they >>> have some list that in the book sorts but when I tried it it came unordered. >>> So after a week of screwing with it, I just gave up on Grails for another >>> few months. >>> >>> ********* Could one of you real experts help this person? And then with >>> what we learn can we do something that helps other not hit it again (maybe a >>> beginners FAQ; maybe I'll even compile it) >>> >>> >>> My guesses on bad sorts: >>> >>> I've seen the sort in the static mapping not work because it returns a Set >>> which has no ordering. I've seen people suggesting ways to make it return a >>> SortedSet (too hard for a newbie) or List. Could that work here? >>> >>> He has dateCreated, lastUpdated as explicit domain fields. Isn't that >>> field or something like that already created by default? Does this create >>> some sort of conflict? >>> >>> ********** >>> Videos are great to pull people in but it's this kind of stuff that pushes >>> people away. >>> >>> >>> >>> On Feb 7, 2011, at 7:43 PM, chamukin32 wrote: >>> >>>> >>>> Thanks for your replays Daniel... >>>> >>>> I added that line as you suggested me, but the error it's kinda the >>>> same: >>>> >>>> Hibernate: >>>> select >>>> comments0_.risk_id as risk1_0_, >>>> comments0_.comment_id as comment2_0_ >>>> from >>>> risk_comments comments0_ >>>> where >>>> comments0_.risk_id=? >>>> order by >>>> comments0_.date_created desc >>>> util.JDBCExceptionReporter Unknown column 'comments0_.date_created' in >>>> 'order clause' >>>> >>>> This would work if i'd try to get the comments like.. Comments.list() or >>>> findAllBy I think......but I want the comments associated to an specific >>>> Issue or Risk.. so i'm getting first the issue or risk: >>>> >>>> def issue = Issue.get(params.id) >>>> >>>> then i just get the comments like: issue.comments (Issue and Risk has >>>> many >>>> comments)... should I re-write my design? or there is another way to >>>> obtain >>>> the comments ordered for an specific issue or comment?? >>>> >>>> I must be doing something wrong... I thinks it is the way i'm trying to >>>> obtaing the comments...my domain class Comment looks like this: >>>> >>>> class Comment { >>>> >>>> String comment >>>> String createdBy >>>> Date dateCreated >>>> Date lastUpdated >>>> >>>> static belongsTo = [Issue,Risk] >>>> static hasMany = [issues:Issue,risks:Risk] >>>> >>>> static constraints = { >>>> comment(nullable:false,maxSize:255) >>>> } >>>> >>>> static mapping = { >>>> sort dateCreated:"desc" >>>> } >>>> } >>>> >>>> what do you think? >>>> >>>> Thx >>>> -- >>>> View this message in context: >>>> http://grails.1312388.n4.nabble.com/Sort-not-working-tp3258369p3265485.html >>>> Sent from the Grails - user mailing list archive at Nabble.com. >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe from this list, please visit: >>>> >>>> http://xircles.codehaus.org/manage_email >>>> >>>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe from this list, please visit: >>> >>> http://xircles.codehaus.org/manage_email >>> >>> >> >> >> > > > > -- > Graeme Rocher > Grails Project Lead > SpringSource - A Division of VMware > http://www.springsource.com > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
In reply to this post by John Fletcher-3
Are you guys joking? There is already an official Grails wiki.
http://grails.org/Documentation On Tue, Feb 8, 2011 at 10:47 AM, John Fletcher <[hidden email]> wrote: > I think in general a wiki is a great thing to accompany a mailing list, > because the same questions often come up repeatedly and you can just say it > perfectly once and for all in the wiki. > > For example, think of the great entry we could have about IDEs :-). > > John --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
I just wanted to say thanks to everyone...
I'm looking right now the links that Peter posted... all comments were very helpfull...i realized that i've got a lot to learn :) Saludos! |
|
In reply to this post by Ken Liu
I guess a lot of people are confused. We definitely need one of these then: http://guides.rubyonrails.org/contribute.html
1) The registration page is now working again. It seemed to be broken a few days ago. 2) How do we keep people from screwing things up (myself included)? 3) The edit button brings up a text box but I'm not sure I understand the markup. Is this http://en.wikipedia.org/wiki/Help:Wiki_markup#Links_and_URLs correct? 4) I assume the User Guide itself cannot be changed. 5) I similarly assume that the left hand side menu cannot be changed. On Feb 8, 2011, at 12:45 PM, Ken Liu wrote: > Are you guys joking? There is already an official Grails wiki. > > http://grails.org/Documentation > > > > On Tue, Feb 8, 2011 at 10:47 AM, John Fletcher <[hidden email]> wrote: >> I think in general a wiki is a great thing to accompany a mailing list, >> because the same questions often come up repeatedly and you can just say it >> perfectly once and for all in the wiki. >> >> For example, think of the great entry we could have about IDEs :-). >> >> John > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
