Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass attributes and other mappings to queries #42

Open
jgaskins opened this issue Feb 7, 2014 · 0 comments
Open

Pass attributes and other mappings to queries #42

jgaskins opened this issue Feb 7, 2014 · 0 comments

Comments

@jgaskins
Copy link
Owner

jgaskins commented Feb 7, 2014

If we pass attributes defined in the mapper to the queries, this will allow us to do several different things:

  • Convert from given attribute on the object to how it is stored in the database a la Allow mapping object attributes to different DB fields #15.
    • This is an important one for Data Mappers to implement. It's one of the primary reasons to use a Data Mapper over an Active Record.
    • This also makes database migrations a lot less of a necessity since if you need to rename something on your model, there isn't a corresponding database change.
  • Determine how to serialize different types of queries
    • Given the following query on a Postgres database: mapper.select { |article| article.author.name == 'Jamie' }
    • If the author attribute is referenced, we could do a JOIN and not only get that article, but side-load the author, as well.
    • If the author is embedded, we would know that it is serialized as JSON and use the appropriate operators to dig into it and retrieve its name attribute.
    • This could also extend to doing things like this to find articles with specific tags: mapper.select { |article| article.tags.any? { |tag| tag == 'perpetuity' } }
  • Passing the class->table mapping will become important once we support mapping to a different table than the class name, as well, so when we do JOIN queries we're able to join the right table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant