Coder Social home page Coder Social logo

activerecord-sort's People

Contributors

bemky avatar malomalo avatar waratuman avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

bemky

activerecord-sort's Issues

Using distinct breaks sorting through hasMany in Postrges

in knotel/knopi:

Deal.sort(assignments: {assigned_at: :desc}).distinct
>> ActiveRecord::StatementInvalid (PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...N "assignments"."deal_id" = "deals"."id" ORDER BY "assignmen...
                                                             ^
: SELECT  DISTINCT "deals".* FROM "deals" INNER JOIN "assignments" ON "assignments"."deal_id" = "deals"."id" ORDER BY "assignments"."assigned_at" DESC LIMIT $1)

it looks like postgres requires assignments.assigned_at to be in select.

If I modify sort_for_relation in https://github.com/malomalo/activerecord-sort/blob/master/ext/active_record/base.rb#L85 and insert:

resource = resource.select(column)
resource = resource.order(Arel::Nodes::Descending.new(column, nulls))

It works as expected, but it breaks count:

Deal.sort(assignments: {assigned_at: :desc}).count
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR:  syntax error at or near "Arel"
LINE 1: SELECT COUNT(#<struct Arel::Attributes::Attribute relation=#...
                              ^
: SELECT COUNT(#<struct Arel::Attributes::Attribute relation=#<Arel::Table:0x00007fcf911f6630 @name="deals", @type_caster=#<ActiveRecord::TypeCaster::Map:0x00007fcf911f6680 @types=Deal(id: uuid, build_type: string, status: string, stage: string, address_street: string, address_city: string, address_state: string, address_submarket: string, address_metro: string, address_postal_code: string, address_country: string, lease_type: string, property_class: string, property_construction: string, property_amenities: string, passenger_elevators: integer, freight_elevators: integer, contact_commitment_conference_rooms: string, contact_commitment_flooring: string, contact_commitment_fronts: string, contact_commitment_ada: string, contact_commitment_pantry: string, contact_commitment_conference_rooms_explanation: text, contact_commitment_flooring_explanation: text, contact_commitment_fronts_explanation: text, contact_commitment_ada_explanation: text, contact_commitment_pantry_explanation: text, created_at: datetime, updated_at: datetime, qualified_at: datetime, term_sheet_signed_at: datetime, lease_signed_at: datetime, drive_url: string, inactive_reason: string, address_market: string, owner_organization: string, accounts_count: integer, tourable_on: date, possession_on: date, tour_instructions: text, occupancy: integer, market_rate: float, target_rate: float)>, @table_alias=nil>, name="*">, #<struct Arel::Attributes::Attribute relation=#<Arel::Table:0x00007fcf8fe9b720 @name="assignments", @type_caster=#<ActiveRecord::TypeCaster::Map:0x00007fcf8fe9b8b0 @types=Assignment(id: uuid, owner_id: uuid, completed_by_id: uuid, deal_id: uuid, title: string, stage: string, order: integer, completed_at: datetime, created_at: datetime, updated_at: datetime, disabled_at: datetime, assigned_at: datetime, snooze_to: datetime)>, @table_alias=nil>, name=:assigned_at>) FROM "deals" INNER JOIN "assignments" ON "assignments"."deal_id" = "deals"."id")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.