package Foo; use Schema; use Fey::ORM::Table; use Fey::SQL; use Fey::Placeholder; my $schema = Schema->Schema(); my $foo_table = $schema->table( 'foo' ); my $bar_table = $schema->table( 'bar' ); my $writer_xref = $schema->table( 'bar_xref' ); has_table $foo_table; my $sql = Fey::SQL->new_select(); $sql->select( 'bar_id' ); $sql->from( $bar_xref ); $sql->where( $bar_xref->column( 'foo_id' ), '=', Fey::Placeholder->new ); has_many 'bars' => ( table => $schema->table('bar'), select => $sql, bind_params => sub { $_[0]->id }, ); 1;