Persons Table
------------------------------------------------------------ id | name | cost_price | sell_price | product_id | ------------------------------------------------------------ 1 person1 10000 20000 1 2 person2 20000 30000 2 3 person3 30000 40000 3
Products Table
-------------- id | name | -------------- 1 product1 2 product2 3 product3My SQL Query
select name, (cost_price - selling_price) as profit, products.name from persons inner join products on persons.product_id = products.id where product.id = 1 order by product.name asc
I fail to replicate this in Data Mapper, this is what I have tried(I have defined the models & their associations properly)
Person.all( # SQL Join equivalent Person.product.id => 1, # products.name how to define that ? # Also can we directly take cost_price-selling_price as profit or # we need to model the resultset ? :fields => ['id', 'name', 'cost_price', 'selling_price'] # How do I order by product.name ? :order => [] )