On Thursday, April 26, 2012 3:22:07 PM UTC-7, Rodrigo Rosenfeld Rosas wrote: > > This is not about laziness. In a far future I hope to get all my > application converted from Grails to Rails. After that I'd like to write a > migration that would rename the "jsec_user" table to "users". I'd only need > to change a single line of code when I do that. >
Using Model.table_name should work fine for that case. > This is not the first project I have this need and I don't think I'm the > only one with such needs. Actually this is far common to anyone used to > deal with SQL and reports. I needed things like that all the time too in my > old job with different projects. > If other Sequel users on this list have a need for this, please speak up. In general, hard coding the table names in queries is unlikely to have a negative effect, and if you choose to rename later, it's not like you won't be able to find related code via grep jsec_user. > Yes, I know, but if this could be added to Sequel, it would be easier for > others to figure out what this method does. I wouldn't know where this > method comes from if I wasn't the one who is requesting it. I mean, if I > was reading someone else's code, I'd look for "as" in the Sequel > documentation and finally would ask here about it. > The assumption that the need of any user should be added to a library for all users leads to bloat. It's not like what you want to do isn't possible currently. It's just that there isn't a shortcut for it. I don't think a shortcut should be added by default, but you are free to add such shortcuts yourself. > It is just that I think this is pretty useful to many people and wouldn't > hurt Sequel anyway. > Most users who submit such feature requests probably feel the same way. :) My issues with adding Model.as: 1) What is the behavior if the model references multiple tables (either FROM and/or JOIN)? 2) What is the behavior if the model already uses an aliased table? 3) There is already a Dataset#as method that does something different, and many Model class methods call the dataset method of the same, so adding a Model.as method that returns a modified dataset would introduce an apparent inconsistency. > Exactly, but it is not great for me to depend on Sequel's internal if I > use something like "where(user1__name)". Also, "user1__name" doesn't make > any sense when reading the code. Alias are meant to give some meaning to > that table role in the query. > Well, you can use the :graph_alias_base option to set the base of the alias name per association. You can't use a hash for eager_graph as you propose, as that is already valid syntax that means something different (cascaded eager loading). Relying on the deterministically generated name is fine, it's not an internal detail that will change. It won't change, you can consider it part of the spec. If you have a real world use case where this is causing problems, please do post it. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/UU2xCg0QBYUJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
