News for hackers. Stuff that matters.
Re:Arel merge, rails' hidden gem by ben_h on Monday July 09, 2012 @10:39AM (#4218389)
Hope was definitely a bad choice of word. By that I meant, the sort of tight query you'd hope an ORM would deliver.

Anyhow, it's a matter of taste, but what may appear at first as hieroglyphics actually is straightforward. It's just that concision here means some packed meaning and some assumed knowledge, so you have to know how to read it. In this case, that's an easy trade-off for me.

I'm not familiar with SQLAlchemy, so I find your example equally hard to read, compounded by there being much more code to spelunk through to understand.

Different strokes and all that, though. There's room for plenty of frameworks :)

Re:Arel merge, rails' hidden gem by sirn on Monday July 09, 2012 @10:51AM (#4218435)
> I'm not familiar with SQLAlchemy, so I find your example equally hard to read, compounded by there being much more code to spelunk through to understand.

If you remove few column definition and setup code, it actually boils down to just:

    class Article(ArticleColumns):
        @property
        def users(self)
            return self.collaborations.join("user").with_entities(User)
    
    class User(UserColumns):
        pass
    
    class Collaboration(CollaborationColumns):
        user = relationship("User", backref="collaborations")
        article = relationship("Article", backref=backref("collaborations", lazy="dynamic"))
    
        @hybrid_property
        def editorial(self):
            return self.role == 'editor'
In which you can now do

    some_article.users.filter(Collaboration.editorial)
which generates similar SQL query as #merge.
Re:Arel merge, rails' hidden gem by zzzeek on Monday July 09, 2012 @10:43AM (#4218406)
It's just a little friendly/competitive poke! Don't take it seriously, I just couldn't resist.

I mostly wanted to demonstrate that the functionality of Rails' merge() can be considered in other ways that are just as succinct.