Comments (3)
What about this:
class Company < ActiveRecord::Base
has_many :company_media
def photos
CompanyMedia.joins(:media).where(company_id: id, media: {actable_type: 'Photo'})
end
end
from active_record-acts_as.
Thanks @hzamani. That works for retrieving photos, but doesn't work when creating them..
from active_record-acts_as.
I haven't tested but I would expect the below to work.
class Company < ActiveRecord::Base
has_many :company_media
has_many :photos, -> { where(actable_type: 'Photo') }, through: :company_media
has_many :videos, -> { where(actable_type: 'Video') }, through: :company_media
end
from active_record-acts_as.
Related Issues (20)
- Support Rails / ActiveRecord 5.0 HOT 3
- Column name collisions in queries HOT 10
- Follow rspec convention when including matchers
- NameError: Undefined local variable or method actable HOT 5
- model.specific returns nil HOT 1
- [Feature Request] Adding accepts_nested_attributes_for actable model HOT 1
- Object does not keeps the attributes submited HOT 1
- Child object does not sets the corrent _type on query HOT 4
- Does not work with rails 5 HOT 12
- Same ID inheritance HOT 4
- [Rails 5] It requires actable when belongs_to_required_by_default is true HOT 1
- Actable model is saved twice HOT 10
- Is there a way I can filter Parent objects with children attribute? HOT 2
- Can't use specific or actable in Parent Object until record is saved HOT 1
- not touching child HOT 1
- Rails 5.1 warnings HOT 5
- It doesn't support with rails 5.1 HOT 1
- uninitialized constant CourseActivity::Actable HOT 1
- Inherit belongs_to through
- belongs_to relationship created by actable?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from active_record-acts_as.