Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 13 08:01

    flash-gordon on main

    Update examples (compare)

  • Aug 09 12:04
    wuarmin commented #407
  • Aug 09 11:40
    flash-gordon commented #407
  • Aug 09 07:02
    wuarmin commented #407
  • Jul 28 23:51
    Clivern starred rom-rb/rom-sql
  • Jul 28 16:44
    elct9620 commented #389
  • Jul 28 16:25
    elct9620 commented #389
  • Jul 28 16:18
    elct9620 commented #389
  • Jul 28 16:15
    elct9620 commented #389
  • Jul 28 14:47
    elct9620 commented #389
  • Jul 21 23:20
    dependabot[bot] labeled #345
  • Jul 21 23:20
    dependabot[bot] labeled #345
  • Jul 21 23:20
    dependabot[bot] opened #345
  • Jul 21 23:20

    dependabot[bot] on bundler

    Bump tzinfo from 1.2.9 to 1.2.1… (compare)

  • Jul 02 06:00
    cuilei5205189 starred rom-rb/rom-rb.org
  • Jun 26 10:04
    chee-k starred rom-rb/rom-sql
  • Jun 14 20:47
  • Jun 01 05:15

    solnic on main

    Switch to peaceiris/actions-gh-… (compare)

  • May 28 10:20

    solnic on main

    Remove GA (compare)

  • May 27 16:41
    dependabot[bot] labeled #344
Ethan Turkeltaub
@ethnt
Hi all, I'm having some issues with self-referential relations
Ethan Turkeltaub
@ethnt
The issue I believe is with using a view, I get the error: NoMethodError: undefined methodpreload_assoc' for #<ROM::Relation::Curried:0x00007f85cd8136e8>`
Calling combine(:regions) on the relation produces that error, but only when view is set. I see someone had this issue in 2017 but I'm not sure if it was ever resolved. I'm on ROM 4.2.1
Piotr Solnica
@solnic
@ethnt add override: true
has_many :regions, view: :children, override: true
Ethan Turkeltaub
@ethnt
@solnic D'oh, thanks :) I'm the person from Discourse with the JSON/dry-types serialization issue, I'll work on reproducing it outside of our app. Would that be an issue I report to dry-types?
Piotr Solnica
@solnic
@ethnt pls report in rom repo, it's most likely an issue in rom
Dawid Lenkiewicz
@dawidlenkiewicz
@gotar ah yeah, good idea to convert ranges to one array with values. I think it fits well in my solution, the ranges won't be really big. Thanks
Ethan Turkeltaub
@ethnt
I have a bit of an ideology question: should I be using repositories for querying data if I'm just replicating the same sort of logic in the relations? For example, if I want to get the posts for a user, I'll be calling posts_repository.for_user(user), which just calls posts_relation.for_user(user). Does this make sense or am I going about this the wrong way?
Piotr Solnica
@solnic
@ethnt what does posts_relation.for_user(user) do?
Ethan Turkeltaub
@ethnt
@solnic it's just posts_relation.where(user_id: user.id)
Piotr Solnica
@solnic
then I'd have that in the repo, and I wouldn't have for_user defined in relation
the only situation where it makes sense to define custom relation views (methods) is when query logic is very complex or you need it for composition with other relation views
Oskar Szrajer
@gotar
sometimes for basics calls you will feel like repo and relations are the same but what distinguish them for me:
  • inside relations you define atomes, and you can chain them (like AR scopes)
  • in repo you use those atoms to build more complex queries and you got tuple (records)
that's how i understand and use them, and this helps to understand this for me
# in relations
def active
  ....
end

def by_id(id)
...
end

# in repo
def [](id)
  users.active.by_id(id).one
end
so you have atoms you chain to build final calls and sometimes they will be like 1-1 repo-relation
but probably @solnic will describe and explain it better
Piotr Solnica
@solnic
yes, primary reason for relation views is chaining and composition
and repos are first and foremost the boundary between your app and persistence
Dawid Lenkiewicz
@dawidlenkiewicz

but shouldn't repositories (in theory) always return "materialized" data ?

Like:

# in relation
def for_user(user)
  where(user_id: user.id)
end

# in repo
def for_user(user)
  posts_relation.for_user(user).to_a
end
Oskar Szrajer
@gotar
yeah
you use relations to build (chain) logic (query) and in repo you finish with objects (tuples)
Ethan Turkeltaub
@ethnt
@solnic @gotar @dawidlenkiewicz I think that makes sense. So a summary would be: use repositories to compose the views from relations and to return materialized data?
@solnic @gotar I've wondered, why is the pattern of [](arg) used a lot with ROM/dry over a different method?
Oskar Szrajer
@gotar
a convention, like to use .() in place of .call
[] can be user as a .call to
but mostly it's user like a key in hash
{a: 1, b: 2}[:a]

and

def [](id)
   ...
end

user[12] # => is like user.find_by_id(12)

not sure it's the best explanation
[6] pry(main)> add = -> (a,b) { a + b}
=> #<Proc:0x00005567f9a1eee0@(pry):6 (lambda)>
[8] pry(main)> add.call(1,2)
=> 3
[9] pry(main)> add.(1,2)
=> 3
[10] pry(main)> add[1,2]
=> 3
Oskar Szrajer
@gotar
so when you used to use [] in a hash, in a procs it's somehow natural (for me) to use like users[12] #=> give me user by ID equal 12
hope it answers to your question somehow
Ethan Turkeltaub
@ethnt
Yes, that makes sense! I was just curious about the backstory :)
Oskar Szrajer
@gotar
for real backstory you will need to do a git blame and find the authors :p
but I hope it gives you some explanation ;]
Piotr Solnica
@solnic
another concept is to use .() shortcut for objects that are pure (so no side-effects), but I failed to use it like that consistently :) I just like typing .() instead of .call :D
S.Tamiya
@ablce9

I have a question here. Basically I have three tables and need to left-join two of them. SQL here MySQL [account]> select email,role,main_email from users left join tenants_users on (tenants_users.user_uuid = users.uuid) left join tenants on (tenants.main_email = users.email);.
I got this instead,

[86] pry(main)> db.from(:users).select(:email).left_join(:tenants_users, user_uuid: :uuid).select_append(:role).left_join(:tenants, main_email: :email)
=> #<Sequel::Mysql2::Dataset: "SELECT `email`, `role` FROM `users` LEFT JOIN `tenants_users` ON (`tenants_users`.`user_uuid` = `users`.`uuid`) LEFT JOIN `tenants` ON (`tenants`.`main_email` = `tenants_users`.`email`)">

I like to replace tenants_users.email with users.email.

I wonder how I can explicitly write left join tenants on (users.email = tenants.main_email) ???
Oskar Szrajer
@gotar
@ablce9 left_join(:tenants, { main_email: :email }, table_alias: :users) i guess
Nikita Shilnikov
@flash-gordon
this is falling back to sequel, rom-sql from master has first class support for it. ATM releasing a matter of a couple of months
Oskar Szrajer
@gotar
but that should do the job as I know
@flash-gordon and how new ROM support for this looks like?
Nikita Shilnikov
@flash-gordon
it's on the changelog
Oskar Szrajer
@gotar
ok :)
Nikita Shilnikov
@flash-gordon
there should be nice examples
Oskar Szrajer
@gotar
yeah :) nice one thx
S.Tamiya
@ablce9
@flash-gordon Thanks. I somehow figures using Sequel.lit(users.email).