Symfony Doctrine LAZY Data loading
up vote
0
down vote
favorite
I want to pass some data to JavaScript but i got empty vars like this
var testsCompany = {};
var testparams = "[{}]";
It is some issue related of lazy data loading in doctrine, i tried to change the fetch attribute value in ManyToOne association but in vain.
This is my code:
<script type="text/javascript">
var testsCompany = "{{ testsCompany|json_encode()|raw}}";
var testparams = "{{ testparams|json_encode()|raw}}";
</script>
This is my entity:
class TestParams
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Many testparams have One test.
* @ORMManyToOne(targetEntity="Tests", inversedBy="testparams",fetch="EAGER")
* @ORMJoinColumn(name="test_id", referencedColumnName="id")
*/
private $test;
/**
* Many testparams have One param.
* @ORMManyToOne(targetEntity="Params", inversedBy="testparams", fetch="EAGER")
* @ORMJoinColumn(name="param_id", referencedColumnName="id")
*/
private $param;
/**
* @var bool
*
* @ORMColumn(name="required", type="boolean")
*/
private $required;
public function __construct()
{
$this->test = new ArrayCollection();
$this->param = new ArrayCollection();
}
public function __toString()
{
return '*';
}
}
and this is the controller code:
/**
* @Route("/generate/{id}", name="prestashoptest_db_generate")
*/
public function generateAction(Request $request)
{
$testId = $request->get('id');
$testRepo = $this->getDoctrine()->getRepository('PrestaShopTestBundle:Tests');
$testParamsRepo = $this->getDoctrine()->getRepository('PrestaShopTestBundle:TestParams');
$testParams = $testParamsRepo->findBy(array("test" => $testId));
$testsCompany = $testRepo->find($testId);
return $this->render('PrestaShopTestBundle:BOTest:generate.html.twig',
array(
"testsCompany" => $testsCompany,
"testParams" => $testParams,
)
);
}
symfony doctrine2 lazy-loading
add a comment |
up vote
0
down vote
favorite
I want to pass some data to JavaScript but i got empty vars like this
var testsCompany = {};
var testparams = "[{}]";
It is some issue related of lazy data loading in doctrine, i tried to change the fetch attribute value in ManyToOne association but in vain.
This is my code:
<script type="text/javascript">
var testsCompany = "{{ testsCompany|json_encode()|raw}}";
var testparams = "{{ testparams|json_encode()|raw}}";
</script>
This is my entity:
class TestParams
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Many testparams have One test.
* @ORMManyToOne(targetEntity="Tests", inversedBy="testparams",fetch="EAGER")
* @ORMJoinColumn(name="test_id", referencedColumnName="id")
*/
private $test;
/**
* Many testparams have One param.
* @ORMManyToOne(targetEntity="Params", inversedBy="testparams", fetch="EAGER")
* @ORMJoinColumn(name="param_id", referencedColumnName="id")
*/
private $param;
/**
* @var bool
*
* @ORMColumn(name="required", type="boolean")
*/
private $required;
public function __construct()
{
$this->test = new ArrayCollection();
$this->param = new ArrayCollection();
}
public function __toString()
{
return '*';
}
}
and this is the controller code:
/**
* @Route("/generate/{id}", name="prestashoptest_db_generate")
*/
public function generateAction(Request $request)
{
$testId = $request->get('id');
$testRepo = $this->getDoctrine()->getRepository('PrestaShopTestBundle:Tests');
$testParamsRepo = $this->getDoctrine()->getRepository('PrestaShopTestBundle:TestParams');
$testParams = $testParamsRepo->findBy(array("test" => $testId));
$testsCompany = $testRepo->find($testId);
return $this->render('PrestaShopTestBundle:BOTest:generate.html.twig',
array(
"testsCompany" => $testsCompany,
"testParams" => $testParams,
)
);
}
symfony doctrine2 lazy-loading
What about controller? It's the place where you fetch data and pass to view, so it may be helpful.
– Jakub Matczak
Nov 7 at 7:58
Ok, i will add the method code
– Mohammad Trabelsi
Nov 7 at 8:00
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to pass some data to JavaScript but i got empty vars like this
var testsCompany = {};
var testparams = "[{}]";
It is some issue related of lazy data loading in doctrine, i tried to change the fetch attribute value in ManyToOne association but in vain.
This is my code:
<script type="text/javascript">
var testsCompany = "{{ testsCompany|json_encode()|raw}}";
var testparams = "{{ testparams|json_encode()|raw}}";
</script>
This is my entity:
class TestParams
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Many testparams have One test.
* @ORMManyToOne(targetEntity="Tests", inversedBy="testparams",fetch="EAGER")
* @ORMJoinColumn(name="test_id", referencedColumnName="id")
*/
private $test;
/**
* Many testparams have One param.
* @ORMManyToOne(targetEntity="Params", inversedBy="testparams", fetch="EAGER")
* @ORMJoinColumn(name="param_id", referencedColumnName="id")
*/
private $param;
/**
* @var bool
*
* @ORMColumn(name="required", type="boolean")
*/
private $required;
public function __construct()
{
$this->test = new ArrayCollection();
$this->param = new ArrayCollection();
}
public function __toString()
{
return '*';
}
}
and this is the controller code:
/**
* @Route("/generate/{id}", name="prestashoptest_db_generate")
*/
public function generateAction(Request $request)
{
$testId = $request->get('id');
$testRepo = $this->getDoctrine()->getRepository('PrestaShopTestBundle:Tests');
$testParamsRepo = $this->getDoctrine()->getRepository('PrestaShopTestBundle:TestParams');
$testParams = $testParamsRepo->findBy(array("test" => $testId));
$testsCompany = $testRepo->find($testId);
return $this->render('PrestaShopTestBundle:BOTest:generate.html.twig',
array(
"testsCompany" => $testsCompany,
"testParams" => $testParams,
)
);
}
symfony doctrine2 lazy-loading
I want to pass some data to JavaScript but i got empty vars like this
var testsCompany = {};
var testparams = "[{}]";
It is some issue related of lazy data loading in doctrine, i tried to change the fetch attribute value in ManyToOne association but in vain.
This is my code:
<script type="text/javascript">
var testsCompany = "{{ testsCompany|json_encode()|raw}}";
var testparams = "{{ testparams|json_encode()|raw}}";
</script>
This is my entity:
class TestParams
{
/**
* @var int
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Many testparams have One test.
* @ORMManyToOne(targetEntity="Tests", inversedBy="testparams",fetch="EAGER")
* @ORMJoinColumn(name="test_id", referencedColumnName="id")
*/
private $test;
/**
* Many testparams have One param.
* @ORMManyToOne(targetEntity="Params", inversedBy="testparams", fetch="EAGER")
* @ORMJoinColumn(name="param_id", referencedColumnName="id")
*/
private $param;
/**
* @var bool
*
* @ORMColumn(name="required", type="boolean")
*/
private $required;
public function __construct()
{
$this->test = new ArrayCollection();
$this->param = new ArrayCollection();
}
public function __toString()
{
return '*';
}
}
and this is the controller code:
/**
* @Route("/generate/{id}", name="prestashoptest_db_generate")
*/
public function generateAction(Request $request)
{
$testId = $request->get('id');
$testRepo = $this->getDoctrine()->getRepository('PrestaShopTestBundle:Tests');
$testParamsRepo = $this->getDoctrine()->getRepository('PrestaShopTestBundle:TestParams');
$testParams = $testParamsRepo->findBy(array("test" => $testId));
$testsCompany = $testRepo->find($testId);
return $this->render('PrestaShopTestBundle:BOTest:generate.html.twig',
array(
"testsCompany" => $testsCompany,
"testParams" => $testParams,
)
);
}
symfony doctrine2 lazy-loading
symfony doctrine2 lazy-loading
edited Nov 7 at 8:01
asked Nov 7 at 7:55
Mohammad Trabelsi
702526
702526
What about controller? It's the place where you fetch data and pass to view, so it may be helpful.
– Jakub Matczak
Nov 7 at 7:58
Ok, i will add the method code
– Mohammad Trabelsi
Nov 7 at 8:00
add a comment |
What about controller? It's the place where you fetch data and pass to view, so it may be helpful.
– Jakub Matczak
Nov 7 at 7:58
Ok, i will add the method code
– Mohammad Trabelsi
Nov 7 at 8:00
What about controller? It's the place where you fetch data and pass to view, so it may be helpful.
– Jakub Matczak
Nov 7 at 7:58
What about controller? It's the place where you fetch data and pass to view, so it may be helpful.
– Jakub Matczak
Nov 7 at 7:58
Ok, i will add the method code
– Mohammad Trabelsi
Nov 7 at 8:00
Ok, i will add the method code
– Mohammad Trabelsi
Nov 7 at 8:00
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Finally i have a solution:
I installed a serializer:
composer require jms/serializer-bundle
configure it :
After you have installed the package, you just need to add the bundle to your AppKernel.php file:
new JMSSerializerBundleJMSSerializerBundle(),
- and combine twig helpers:
<script type="text/javascript">
var testsCompany = {% autoescape %}{{ testsCompany|serialize|raw }}{% endautoescape %};
var testParams = {% autoescape %}{{ testParams|serialize|raw }}{% endautoescape %};
</script>
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Finally i have a solution:
I installed a serializer:
composer require jms/serializer-bundle
configure it :
After you have installed the package, you just need to add the bundle to your AppKernel.php file:
new JMSSerializerBundleJMSSerializerBundle(),
- and combine twig helpers:
<script type="text/javascript">
var testsCompany = {% autoescape %}{{ testsCompany|serialize|raw }}{% endautoescape %};
var testParams = {% autoescape %}{{ testParams|serialize|raw }}{% endautoescape %};
</script>
add a comment |
up vote
0
down vote
accepted
Finally i have a solution:
I installed a serializer:
composer require jms/serializer-bundle
configure it :
After you have installed the package, you just need to add the bundle to your AppKernel.php file:
new JMSSerializerBundleJMSSerializerBundle(),
- and combine twig helpers:
<script type="text/javascript">
var testsCompany = {% autoescape %}{{ testsCompany|serialize|raw }}{% endautoescape %};
var testParams = {% autoescape %}{{ testParams|serialize|raw }}{% endautoescape %};
</script>
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Finally i have a solution:
I installed a serializer:
composer require jms/serializer-bundle
configure it :
After you have installed the package, you just need to add the bundle to your AppKernel.php file:
new JMSSerializerBundleJMSSerializerBundle(),
- and combine twig helpers:
<script type="text/javascript">
var testsCompany = {% autoescape %}{{ testsCompany|serialize|raw }}{% endautoescape %};
var testParams = {% autoescape %}{{ testParams|serialize|raw }}{% endautoescape %};
</script>
Finally i have a solution:
I installed a serializer:
composer require jms/serializer-bundle
configure it :
After you have installed the package, you just need to add the bundle to your AppKernel.php file:
new JMSSerializerBundleJMSSerializerBundle(),
- and combine twig helpers:
<script type="text/javascript">
var testsCompany = {% autoescape %}{{ testsCompany|serialize|raw }}{% endautoescape %};
var testParams = {% autoescape %}{{ testParams|serialize|raw }}{% endautoescape %};
</script>
answered Nov 7 at 9:51
Mohammad Trabelsi
702526
702526
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53185411%2fsymfony-doctrine-lazy-data-loading%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What about controller? It's the place where you fetch data and pass to view, so it may be helpful.
– Jakub Matczak
Nov 7 at 7:58
Ok, i will add the method code
– Mohammad Trabelsi
Nov 7 at 8:00