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
Lets say i have the following objects :-

Orders : A and B
Items : X, Y and Z

Now Order A might contain multiple quanties of items X but each distinct item x will have a unique serial number.

So, if order A has 3 quantities of items X, in reality it ontains 3 different items with the same name but different manufacturing id/serial number like

item X with Serial number 1
item X with Serial number 2
item X with Serial number 3

And they are all linked to Ordex A which has a unique serial number.

A good example of a many to many relationship would be an employee and a team in an orgrnization where employees work as part of multiple teams.