Question: Each time I run a test from my IDE I get the error

```
java.lang.IllegalStateException: Missing the '-javaagent' JVM argument. 

```

If I create a run config and add the jvm arg everything is fine. However, the next time I run a test on the fly that is not a pre-configured run config I get the error again.

I thought maybe I could use `@BeforeClass` to load the java agent dynamically. e.g.

```
@BeforeClass
public void loadAgent() {
    String nameOfRunningVM = ManagementFactory.getRuntimeMXBean().getName();
    String pid = nameOfRunningVM.substring(0, nameOfRunningVM.indexOf('@'));
    VirtualMachine vm = VirtualMachine.attach(pid);

    Class klass = JavaAgent.class;
    CodeSource codeSource = klass.getProtectionDomain().getCodeSource();
    String agentJar = codeSource.getLocation().getPath();

    vm.loadAgent(agentJar, "");
    vm.detach();
}

```

(maybe using a test listener might mean I don't copy and paste the code into every test class)

This works but it doesn't seem quite right.

Is there a way to do this without needing the pid?

Or is there a fundamentally better alternative to doing this?

Answer: 
what I do is that I take it as *orders -> order\_items -> items*. An Order can has many Order Items and every Order Item is belongs to a Item.

the tabe stucture should be

`orders`

* id
* customer\_id
* date

`order_items`

* id
* order\_id
* item\_id
* qty
* price

`items`

* id
* name
* price
* stock
* supplierId
* date

And in the code you can do something like this

**App/Order**

```
class Order extends Model {

   public function orderItems(){
      $this->hasMany(OrderItem::class);
   }
}

```

**App\OrderItem**

```
class OrderItem extends Model{

    public function order(){
      $this->belongsTo(Order::class);
    }
    public function item(){
      $this->belongsTo(Item::class);
    }
}

```

**App\Item**

```
class Item extends Model{

    public function orderItems(){
      $this->hasMany(orderItem::class)
    }

}

```

hope this help! 

PS - follow table\_name\_singular\_id naming convention as foreign key names in order for the laravel eloquent to work without passing column names
As you might know many to many relationship can be achieved using **Pivot** table.

Definitely it will be a **many to many relationship** only if you store the quantity of items as a value in **Pivot** table.

The schema can be as follows -

*Order*

* id
* name

*Item*

* id
* name

*Pivot*

* order\_id
* item\_id
* quantity