Datamapper의 클래스에서 연관을 정의 할 때 기본적으로 관련 모델 데이터를 얻지 못하는 것 같습니다. 예를 들어DataMapper (Ruby)로 관련 모델 가져 오기
:
class Song
include DataMapper::Resource
property :id, Serial
property :name, String
property :artist_id, Integer
belongs_to :artist
end
class Artist
include DataMapper::Resource
property :id, Serial
property :name, String
has n, :songs
end
Song.get(params[:id]).to_json
노래 쿼리는 기본적으로 예술가 테이블과 조인 수행하지 않습니다. 위의 예에서 노래를 따라 아티스트와 어떻게 합치고 참여할 수 있습니까? 두 클래스 중 하나만 쿼리하면 별도로 작동합니다. 이것은 DataMapper를 통해 생성되지 않은 기존 db입니다.
미리 감사드립니다.