logo
down
shadow

Filter relationship in rails json api using many to many


Filter relationship in rails json api using many to many

By : Bart Szymowski
Date : November 19 2020, 03:01 PM
seems to work fine As you use cancancan you can filter it through ability in AccountSerializer
code :
has_many :projects do
  ability = Ability.new(scope)
  @object.projects.select{ |p| ability.can?(:read, p) }
end


Share : facebook icon twitter icon
Filter based on model attribute has_many relationship through, rails 3?

Filter based on model attribute has_many relationship through, rails 3?


By : Sid Bora
Date : March 29 2020, 07:55 AM
around this issue You want current_user.assets, then your scopes should work.
Oh, but you want the user_assets. Hmm. I think you need the :include clause to find() but where to put it, I can't be arsed to think of right now.
code :
current_user.user_assets.find(:all, :include => :assets).where('asset.live=?', true)
Weird problem with json rendering of model of relationship in Rails 3.0.4

Weird problem with json rendering of model of relationship in Rails 3.0.4


By : user2796005
Date : March 29 2020, 07:55 AM
hope this fix your issue solved the problem by not rendering the patient.todays_order "relationship", instead i'm rendering result of an AR query. So I think you cant render a relationship object directly in rails.
Filter json render in Rails

Filter json render in Rails


By : user2867999
Date : March 29 2020, 07:55 AM
To fix the issue you can do What is the best way if i would like to only return :id and :name fields in JSON , You can pass :methods to to_json / as_json
code :
format.json do
  render :json => @contacts.map { |contact| contact.as_json(:only => :id, :methods => :name) }
end
format.json do
  render :json => @contacts.map { |contact| {:id => contact.id, :name => contact.name} }
end
Rails: Filter has_many relationship by another Foreign Key

Rails: Filter has_many relationship by another Foreign Key


By : user3357240
Date : March 29 2020, 07:55 AM
will help you I personally prefer the scopes (approach 4) or class methods.
I believe in normal case, your approach 4 and approach 1 should generate the same SQL statement if you use chained scope, like:
code :
project.employees.from_department(department_id)
How can I filter a field from a Many To Many relationship in Rails?

How can I filter a field from a Many To Many relationship in Rails?


By : Ville Gillström
Date : March 29 2020, 07:55 AM
wish helps you How are your models set up? From what you're describing, you need to specify that you're joining Table1 and Table3, and filtering by current user. Something like:
code :
class Foo
  has_many :bars
end

class Bar
  belongs_to :foo
  belongs_to :user
end

# Joining and filtering
Foo.joins(:bars).where(bars: { user: @current_user })
Related Posts Related Posts :
  • In Ruby On Rails CLI, how can I list Helper Paths?
  • How to prevent nested create failing with scoped has_many in ActiveRecord?
  • Rails cant assign attributes for new entity
  • activeadmin has_many hide remove button
  • Ruby on Rails: How can I override a method from a gem while calling the super method
  • Dockerized Selenium with rails tests
  • View 3rd party api code
  • add a if condition to rails delete function and pass a alert message to view
  • i18n dont find the translation
  • Upgrading passenger to 5.1.11 breaks setup with 403
  • How to handle images in a Rails / Webpacker / React app?
  • Rails check_box_tag - save array into Postgres
  • custom query in active record with multiple joins
  • Testing Rails API controller POST with RSpec
  • Download a CSV file from FTP with Ruby on Rails and Update Existing Records
  • Rails group_id to Insert statement
  • How to skip validation on update?
  • active model serializer has_many association not working
  • Time.use_zone is ignored during active record query
  • referencing foreign key attributes rails
  • Passing Post request through postman for has_many association in rails
  • link_to in data-content for a bootstrap 4 popover
  • rubyzip extracts empty file in activejob
  • Why is Rails running in development mode during rake test task?
  • Rspec testing model with null: false constraint
  • Specify UTC Offset instead of timezone to ActiveSupport::TimeWithZone
  • Carry Sass variables across all stylesheet files in Rails
  • Each loop outputs an unwanted dump of the records after the loop
  • Suddenly can't push to heroku: "unable to negotiate key exchange method"
  • Mapping ActiveRecord as dynamic key value pair on Rails
  • Rails form with checkboxes from enum (hash)
  • How to compare two items within Ruby on Rails?
  • Rails Routes - How to get nested IDs from URI Pattern
  • Optimize database query for time series data retrieving using postgresql and ruby on rails
  • How to store cryptocurrency balance without causing floating point errors in ruby/rails
  • unknown attribute in rails 5
  • undefined method `new' for #<Grease::Adapter(Less::Rails::ImportProcessor)
  • Get values without using sessions
  • Compatibility issue when using rails_admin_email gem
  • Passing values between objects rails
  • Should I check for updated attributes before making a db call?
  • Using minitest to test that hash contains array values of specific size
  • No implicit conversion of Array into String - Rails Migration
  • Headless Chrome with Rspec database connection not working
  • rails 5 User.find(params[:user_id]) nill
  • Rails scopes using many-to-many and joins
  • Link_to root_path not working in mail view
  • Status code 302 does not redirect after a POST call
  • validation errors are added only in production env
  • rails redirect user to profile page after destroy action
  • Incrementing a field with a Ruby on Rails call back
  • Rails+resque background job import not adding anything to the database
  • Rails Form Builder - How to place html attributes
  • Upgrading my app to Rails 5. Not sure what to make of errors on bundle install
  • Spree active menu
  • RSpec: Avoid using allow any instance of to receive
  • RSpec: Test a create action method in controller
  • Rollback gems according to version in Gemfile.lock
  • Send different confirmation emails with Devise
  • Cannot access children in after_create method in Rails 5
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org