Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Sep 28 13:06
    repomaa synchronize #203
  • Sep 28 12:31
    repomaa synchronize #203
  • Aug 27 15:16
    fridgerator closed #250
  • Aug 27 15:15
    fridgerator closed #254
  • Jul 14 06:10
  • Jun 18 20:25
    hutou edited #254
  • Jun 18 20:23
    hutou edited #254
  • Jun 18 08:26
  • Jun 17 20:18
    hutou opened #254
  • Jun 11 20:44
    fridgerator closed #253
  • May 06 16:09
    hutou opened #253
  • Apr 14 11:40
  • Feb 23 17:14
    fridgerator closed #251
  • Feb 23 17:13
    fridgerator closed #252
  • Feb 22 14:58
    wmoxam opened #252
  • Feb 19 00:50
  • Jan 28 14:29
    hutou opened #251
  • Nov 30 2020 21:14
  • Nov 28 2020 17:00
  • Nov 10 2020 20:33
    hutou opened #250
Zach Baylin
@zbaylin
Hey everyone, for some reason I keep getting this weird preload bug with crecto
running this query, the #employer prop for every user is the same
      query = Query
                  .join(:memberships)
                  .preload(:employers)
                  .where("user_groups.group_id = ?", group.id)
      users = Repo.all(User, query)
      users.to_json
even though some should be null, and only one user has an employer
sample response
[
    [
        {
            "email": "test@test.com",
            "firstname": "Alphonso",
            "lastname": "Johnson",
            "location": "McDonalds",
            "address": "155 Spalding Creek Ct.",
            "title": "Manager",
            "id": 3
        }
    ],
    [
        {
            "email": "test@test.com",
            "firstname": "Alphonso",
            "lastname": "Johnson",
            "location": "McDonalds",
            "address": "155 Spalding Creek Ct.",
            "title": "Manager",
            "id": 3
        }
    ],
    [
        {
            "email": "test@test.com",
            "firstname": "Alphonso",
            "lastname": "Johnson",
            "location": "McDonalds",
            "address": "155 Spalding Creek Ct.",
            "title": "Manager",
            "id": 3
        }
    ],
    [
        {
            "email": "test@test.com",
            "firstname": "Alphonso",
            "lastname": "Johnson",
            "location": "McDonalds",
            "address": "155 Spalding Creek Ct.",
            "title": "Manager",
            "id": 3
        }
    ],
    [
        {
            "email": "test@test.com",
            "firstname": "Alphonso",
            "lastname": "Johnson",
            "location": "McDonalds",
            "address": "155 Spalding Creek Ct.",
            "title": "Manager",
            "id": 3
        }
    ],
    [
        {
            "email": "test@test.com",
            "firstname": "Alphonso",
            "lastname": "Johnson",
            "location": "McDonalds",
            "address": "155 Spalding Creek Ct.",
            "title": "Manager",
            "id": 3
        }
    ]
]
even though preloading employments returns this:
[
    [],
    [
        {
            "user_id": 16,
            "employer_id": 3
        }
    ],
    [],
    [],
    [],
    []
]
Zach Baylin
@zbaylin
my User model looks like this:
      has_many :employments, Employment
      has_many :employers, Employer, through: :employments
any ideas?
I'd really appreciate it :)
Jon
@faultyserver
is the sample response what you're actually getting out?
or is the second sample what you're getting?
either way, it looks like you're mapping over the results somewhere to get an array out. Can we see that code?
Zach Baylin
@zbaylin
is the standard way to insert multiple records just to iterate over an array of them and Repo.insert each?
or can the Repo generate prepared statements to insert multiple records at once?
Nick Franken
@fridgerator
Right now thats the only way, I made an issue for this but it hasn't been addressed by anyone yet : Crecto/crecto#205
Zach Baylin
@zbaylin
ok cool
it would be more efficient for the other way, I'd assume
Nick Franken
@fridgerator
yeah I would assume so
Zach Baylin
@zbaylin
is there a way to distinct on one column while selecting * ?
every time I do Query.distinct, it only selects that column

for example:

      query = Query.distinct("category_string")
                   .select(["*"])

generates SELECT DISTINCT category_string FROM questions

Nick Franken
@fridgerator
hrmm, I would have to look into that
Jon
@faultyserver
https://stackoverflow.com/a/6127471 seems like that's not a thing that SQL supports directly
I remember having issues trying to do the same thing in the past
Postgres has DISTINCT ON, but that's a non-standard extension
Joakim Repomaa
@repomaa
hey! i have a JSON::Any field and i'm getting the following error when using it: The Eeschema documentation describes this intermediate netlist and gives examples
lol
paste fail
this: Unhandled exception: :data type must be one of String, Int64, Int32, Int16, Float32, Float64, Bool, Time, (Int32 | Int64), (Float32 | Float64), JSON::Any, (Int16 | Int32 | Int64 | Int8 | String | Nil), Array(String), Array(Int64), Array(Int32), Array(Int16), Array(Float32), Array(Float64), Array(Bool), Array(Time), Array(Int32 | Int64), Array(Float32 | Float64), Array(JSON::Any), Array(Int16 | Int32 | Int64 | Int8 | String | Nil) (Crecto::InvalidType)
which is weird because it is one of those types since JSON::Any is listed
Joakim Repomaa
@repomaa
my bad
had to use Json as type
Gian D
@fusillicode_twitter
hi guys sorry for the bother :(
I'm getting Unhandled exception: cannot execute UPDATE in a read-only transaction when I try to perform an update via Repo.update!(record)
But I'm not using any transaction in my code 🤔
I've also tried Repo.update(record) (i.e. without the !) but unfortunately the result doesn't change
Jon
@faultyserver
could it be a database set up thing?
like your user doesn't have permissions to write to the database/table?
i don't actually know what error would be raised in that case, but it might be that?
Gian D
@fusillicode_twitter
@faultyserver somehow the problem seems to be related to running inside a docker container 🤔
Nick Franken
@fridgerator
@jreinert I added a section to the docs for the "grouped wheres" feature, let me know if this look good : https://www.crecto.com/crecto-repo-query#nested-grouped-queries
Zach Baylin
@zbaylin
Hey guys -- not sure if this is expected behavior, but whenever I use #distinct(x) on a query with Crecto, only that field x is SELECTed. I tried to override this with #select([*]) but that didnt fix it. Is this a bug or am I querying wrong?
right now I'm fixing this using the #uniq method for arrays but I assume this is measurably slower than the PSQL implementation
Nick Franken
@fridgerator
try using group_by, does that give desired results? https://www.crecto.com/crecto-repo-query#group_by
Zach Baylin
@zbaylin
shoot did I ask before -- very sorry I must have forgotten
ah looks like I did -- again my apologies
yeah I guess I'm looking for Postgres' DISTINCT ON. I never realized the differentiation.
Nick Franken
@fridgerator
no worries :thumbsup:
Joakim Repomaa
@repomaa
@fridgerator LGTM!