impress/app/models/swf_asset_parent.rb

12 lines
402 B
Ruby

module SwfAssetParent
def swf_assets
rels = Table(ParentSwfAssetRelationship.table_name)
type = self.class::SwfAssetType
ids = ParentSwfAssetRelationship.
where(rels[:parent_id].eq(id).and(rels[:swf_asset_type].eq(type))).
select(rels[:swf_asset_id]).
all.map(&:swf_asset_id)
assets = Table(SwfAsset.table_name)
SwfAsset.where(assets[:id].in(ids)).all
end
end