Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

phx93

Experience

2,690

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 24 Lessons Completed
  • 0 Favorites

12th October, 2017

phx93 left a reply on DDD & DB Transactions (unit Of Work?) • 2 months ago

@martinbean How should I handle transactions then? I only need to call the uow class when in need of transactions. This isn't a full blown UoW pattern but I didn't come up with any better naming for this. Maybe I should have named the class 'TransactionService' instead or something.

phx93 left a reply on DDD & DB Transactions (unit Of Work?) • 2 months ago

Ended up doing this:

class OrderService
{
    ...
    public function startNewOrder($order, $facility_id)
    {
         $this->uow->beginTransaction();

         try {
             $order = $this->order->create($order);
             $this->orderEvent->createFirst($order['id'], $facility_id);
             $this->uow->commit();
         } catch (Throwable $e) {
             $this->uow->rollback();
             throw $e;
         }
    }
}

10th October, 2017

phx93 started a new conversation DDD & DB Transactions (unit Of Work?) • 2 months ago

I'm using DDD (Service -> Repository -> Model) and MVC.

Where should I place my transactions (maybe unit of work lite)? Controllers? Services?

The repositories doesn't seem like a good place since a service might use multiple repositories to create a complete domain object. In e.g. when calling startNewOrder on the OrderService, it creates both a Order and OrderEvents using respectively repository. This needs to happen in the same database transaction.

Doing this in the service seems a bit dirty to me:

class OrderService
{
    ...
    public function startNewOrder($order, $facility_id)
    {
         DB::beginTransaction();
         
         try {
             $order = $this->order->create($order);
             $this->orderEvent->createFirst($order['id'], $facility_id);
         } catch (Exception $e) {
             DB::rollback();
             throw $e;
         }
    }
}

7th June, 2017

phx93 left a reply on Stateless Repository Design • 6 months ago

Bump

6th June, 2017

phx93 started a new conversation Stateless Repository Design • 6 months ago

Hi! Many of the tutorials and packages for repositories in the community are stateful. What I mean by that is they hold an instance of a model and then mutates it (either directly or via criterias) and when executing the query (->find()/->findBy()/->count() etc) they reset the model in the repository. This seems dangerous to me since the instance may change unexpectedly if I use it in a middleware.

Because of this I would like to not set the constraints on the repository it self but rather have a DTO or some other intermediary class storing the constraints. AND still keep the methods on the repository chainable.

To clearify, I want to achieve a stateless reposiotry with chainable methods.

$user_repo->status('draft')->publishedBefore('2017-06-01')->fetch()

9th February, 2017

phx93 left a reply on Grouping Data In Same Column • 10 months ago

@w1n78 Hmm I think you misunderstood me. I get the same output as before. I don't get the count for every combination of attribute_1 and attribute_2.

I can solve it by using a subquery for each attribute in the select statement but it is not ideal since I need to do several joins repetitive joins in each subquery. (The real query I'm trying to perform is much more complex and therefore it matters)

8th February, 2017

phx93 left a reply on Grouping Data In Same Column • 10 months ago

@w1n78 but values table only have one ID column. I want to get the count for the combinations of ``values.id

phx93 started a new conversation Grouping Data In Same Column • 10 months ago

I have two tables items and values they are related to each other via a pivot table item_value(many-to-many). I can easy get the number of items associated with each value by grouping the query.

SELECT `values`.id as value_id, count(items.id) as item_count
FROM items
INNER JOIN item_value ON item_value.item_id = items.id
INNER JOIN `values` ON item_value.value_id = `values`.id
GROUP BY value_id

But now I want to group some of combinations of values togehter. So the output becomes like this:

| value_id_1 | value_id_2 | item_count |
---------------------------------------
|  1  |  2  |  22  |
|  1  |  3  |  13  |
|  1  |  4  |  0   |

Where do I begin?

31st August, 2016

phx93 left a reply on Relationship Between Three Models • 1 year ago

@edoc You mean like

$item->with('values.attribute')->where('id', 2)->first()->groupBy('attribute_id');
$q->values->groupBy('attribute_id');

Hmm that kind of solves my problem but the I would prefer if the attribute data would reside on the top level. So I could access data on attribute like

$item->attributes->values  // Get all values associated with attribute
$item->attribute->name // Get attribute name
=> [
     1 => [
       [
         "id" => 1,
         "name" => "ral",
         "attribute_id" => 1,
         "attribute" => [
           "id" => 1,
           "name" => "color",
         ],
       ],
       [
         "id" => 2,
         "name" => "orange",
         "attribute_id" => 1,
         "attribute" => [
           "id" => 1,
           "name" => "color",
         ],
       ],
     ],
     2 => [
       [
         "id" => 4,
         "name" => "standard",
         "attribute_id" => 2,
         "attribute" => [
           "id" => 2,
           "name" => "system",
         ],
       ],
     ],
   ]

phx93 left a reply on Relationship Between Three Models • 1 year ago

No unfortunately that doesn't work...

phx93 left a reply on Relationship Between Three Models • 1 year ago

Bump. Anyone?

30th August, 2016

phx93 left a reply on Relationship Between Three Models • 1 year ago

How does Eloquent build the object from the two queries which being executed $item->with('values.attribute')->where('id', 2)->get();? If it's possible two transform the result in the same way it can resolve my issue.

phx93 left a reply on Relationship Between Three Models • 1 year ago

Please elaborate.

phx93 left a reply on Relationship Between Three Models • 1 year ago

Anyone?

phx93 left a reply on Reset Input File • 1 year ago

I would suggest something more generic: this.$data = this.$options.data();

phx93 left a reply on Relationship Between Three Models • 1 year ago

@tomi No this is not an polymorphic relation.

phx93 started a new conversation Relationship Between Three Models • 1 year ago

DATABASE items id - integer name - string values id - integer attribute_id - integer value - string attributes id - integer name - string attribute_item attribute_id - integer item_id - integer item_value value_id - integer item_id - integer

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.