Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 891315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:52:13+00:00 2026-05-15T13:52:13+00:00

how do I change my activerecord model default behavior for the find method? For

  • 0

how do I change my activerecord model default behavior for the find method?
For example, i want to search for all books inside drupal nodes database, but drupal uses only one table for all data, and uses the ‘type’ column to find out the type

class Book < ActiveRecord::Base
  set_table_name 'node'

  def find(*args)
    :conditions => {:type => 'book'}
    super
  end
end

this is the correct approach to solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:52:14+00:00Added an answer on May 15, 2026 at 1:52 pm

    I’ve solved this creating a model for Node and using named_scopes

    the result was this

    class Node
      set_table_name 'node'
      set_primary_key 'nid'
      named_scope :book, :conditions => {:type => 'book'}
    
      # if i don't overwrite this method, i would get an error when i try to use the type column
      def self.inheritance_column
        "rails_type"
      end
    end
    

    it works, but doesn’t look like the rails way of doing stuff. If I get enought time soon, I’ll try to write a library to access drupal data using something like acts_as_drupal_node

    now i can fetch all book entries using:

    @books = Node.book.all
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to change the default statement that ActiveRecord uses to query a model's
If I have a Model like the following example class Person < ActiveRecord::Base has_many
I've got a pretty basic static method on an ActiveRecord model: #./app/models/comic.rb class Comic
If a model changes an attribute locally, then changes it back, ActiveRecord doesn't send
The error shows this code can not rollback: class AddCountToTag < ActiveRecord::Migration def change
Change all links that have an image in it to: javascript(alert(thehref)); eg. <a href=/galleries/anna-leah-111827/image01.html><img
I change schema.yml from time to time and execute: symfony propel:build-all-load but the lib/_model
I'm using Rails 3 w/ Mongoid, (so no ActiveRecord). Mongoid uses ActiveModel's to_json method,
I added a counter cache called comments_count : class AddCommentsCountToMicroposts < ActiveRecord::Migration def change
I have this code in my user model: class User < ActiveRecord::Base attr_accessible :email,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.