Synthetic fields
Hi. I need to define a synthtic field for a Sequel::Model source dataset. I'd like getting a sum field with any Model query. How can it be done? Thank you very much. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/58014b6b-8182-4e69-8b23-179849c3f7fan%40googlegroups.com.
Re: Synthetic fields
El miércoles, 13 de octubre de 2021 a las 15:43:39 UTC+2, Jeremy Evans escribió: > On Wed, Oct 13, 2021 at 1:49 AM David Espada wrote: > >> Hi. >> >> I need to define a synthtic field for a Sequel::Model source dataset. I'd >> like getting a sum field with any Model query. How can it be done? >> > > It sounds like you want to add a SELECTed expression to the model's > dataset: > > class ModelName < Sequel::Model(DB[:table].select_append(some_expression)) > end > Thank you very much :D I have found a problem with my "cooked" dataset. Here is the code for composing it: class Gasto < Sequel::Model set_dataset(dataset.select(*dataset.columns.map {|c| Sequel.qualify(:gastos, c)}). left_join(dataset.exclude(id: :gastos__id).as('g'), prevision_id: :gastos__prevision_id). select_append {sum(:g__importe_divisa).as(:otros_gastos)}. group_by(:gastos__id)) end When I try to save data on this model here is the result of "puts dataset.sql": - SELECT * FROM (SELECT "gastos"."id", "gastos"."factura_proveedor_id", "gastos"."prevision_id", "gastos"."divisa_id", "gastos"."cambio_gasto", "gastos"."importe_divisa_base", "gastos"."importe_divisa", "gastos"."cuenta_gasto", "gastos"."dato_facturacion_compra_id", "gastos"."concepto_id", "gastos"."contraccion_id", "gastos"."_type", "gastos"."codigo_analitica", "gastos"."parent_id", "gastos"."repartido", "gastos"."entidad_reparto", "gastos"."criterio_reparto_id", "gastos"."tipo_entidad", "gastos"."clave_busqueda_reparto_id", "gastos"."valor_reparto_id", sum("g"."importe_divisa") AS "otros_gastos" FROM "gastos" LEFT JOIN (SELECT * FROM "gastos" WHERE (("gastos"."_type" IN ('factura_proveedor_gasto')) AND ("id" != "gastos"."id"))) AS "g" ON ("g"."prevision_id" = "gastos"."prevision_id") WHERE ("gastos"."_type" IN ('factura_proveedor_gasto')) GROUP BY "gastos"."id") AS "gastos" LIMIT 1; -- It works good when executed directly in PostgreSQL. But when doing the save in Sequel it raises the error: Sequel::DatabaseError: Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near "(" Position: 13 from org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(org/postgresql/core/v3/QueryExecutorImpl.java:2532) Caused by Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near "(" Position: 13 from org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(org/postgresql/core/v3/QueryExecutorImpl.java:2532) Caused by Java::OrgPostgresqlUtil::PSQLException: ERROR: syntax error at or near "(" Position: 13 from org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(org/postgresql/core/v3/QueryExecutorImpl.java:2532) - Is there a bug? Anything I do wrong? Thank you again for your work and tricks :) -- David > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/bbfc518c-369f-4dbc-afe6-969daa275e63n%40googlegroups.com.
"delay_add_association" plugin and one_to_one relationship
Hi all. There is a good little Sequel plugin called "delay_add_association" that avoids persistence when adding a child (one_to_many) to an entity. That is good in my system, because I like to have a consistent object representation without persisting nothing until the end of the work cycle. But I have a problem for generalizing that behaviour with one_to_one relations. In that case I can't do assignation between entities avoiding persistence. Can we have a similar solution for one_to_one as in one_to_many? I think that consistent behaviour is good for Sequel practices :) Thank you very much. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
Re: "delay_add_association" plugin and one_to_one relationship
2016-08-31 16:00 GMT+02:00 Jeremy Evans : > I suppose that is something I would consider as an addition to > delay_add_association. Do you want to work on a pull request for it? > > I have seen lightly the code and... it frightens me a little, but can try it :) What I wish is having changed behaviour in all cases, when entity is new and when is not. If you assign a related entity in ANY case, persistence and linking is delayed until main (root) entity is persisted. What do you think of that option? Thank you. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
Re: "delay_add_association" plugin and one_to_one relationship
2016-08-31 18:40 GMT+02:00 Jeremy Evans : > That's certainly not the behavior of delay_add_association in the *_many > association case, so it wouldn't make sense for it to be the default in the > one_to_one case. If you want that behavior, you can probably write your > only plugin, or just do: > > plugin :instance_hooks > > def association=(v) > after_save_hook{super} > end > =8) Is this code valid for all association types? If so, great! I'll try it. Thank you very much. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
Re: "delay_add_association" plugin and one_to_one relationship
2016-09-01 10:34 GMT+02:00 David Espada : > > 2016-08-31 18:40 GMT+02:00 Jeremy Evans : > >> plugin :instance_hooks >> >> def association=(v) >> after_save_hook{super} >> end >> > > I'll try it. Thank you very much. > I have tested and it doesn't wotk :( I have not found any reference to association= method in Sequel code. What is the matter? I don't understand. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
Re: "delay_add_association" plugin and one_to_one relationship
2016-09-01 10:51 GMT+02:00 David Espada : > I have tested and it doesn't wotk :( > Ouch! Now I understand that your example is not generic code, but a redefinition of specific association code. Sorry :) -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
Object freeze and data reading
Hi all. I have a little problem reading data objects inside a frozen object. If I have a one_to_many relationship between Foo and Bar models, this code fails without a good reason (IMHO): foo.freeze foo.bars Problem is in line lib/sequel/model/associations.rb:1791 of Sequel code. Any clue for this behaviour? Thank you very much. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
Re: Object freeze and data reading
2017-01-13 16:22 GMT+01:00 Jeremy Evans : > Are you running the current version of Sequel? I remember fixing an issue > like this sometime in the past. The line number you give doesn't really > make sense to cause the issue in the current code. If you are running the > current version, please post a minimal self contained example showing the > problem, and a full backtrace, and I should be able to debug. > Here it is: >8 require 'sqlite3' require 'sequel' DB = Sequel.connect('sqlite://companies') DB.create_table :companies do primary_key :id String :name end DB[:companies].insert(name: 'Acme') DB.create_table :positions do primary_key :id String :name foreign_key :company_id, :companies end DB[:positions].insert(name: 'CEO', company_id: DB[:companies].first[:id]) DB[:positions].insert(name: 'CTO', company_id: DB[:companies].first[:id]) class Company < Sequel::Model one_to_many :positions def validate super errors.add(:bla) if positions.size > 2 end end class Position < Sequel::Model many_to_one :company end c = Company.first c.freeze -->8 Greets. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
Re: Object freeze and data reading
2017-01-16 21:40 GMT+01:00 Jeremy Evans > Thanks. This does appear to be a bug, caused because the associations > hash was frozen before validation (freeze validates), when it probably > shouldn't be frozen until after. > .../... > You could work around this issue by overriding Company#freeze to call > positions before calling super. > Thank you. I have a work around applied already. It is enough that it is solved by now ;) Greets. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To post to this group, send email to sequel-talk@googlegroups.com. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
Eager loading models
Hi everybody. If I have this simple model: -- class Operator < Sequel::Model one_to_many :directions end class Direction < Sequel::Model many_to_one :operator end -- I'd like to load an operator with all their directions in one quey. How can I do it with :eager options. :eager option is not usable in this case and I don't know it there is any other possibility. Thank you very much. -- David -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/b1ada8ad-bf4a-42ca-ba3d-cf2a718721d6o%40googlegroups.com.
Best option for validating all date fields in a model by default
Hi. I use Sequel with Postgresql and I am getting a postgresql exception when passing to any date field a value like "02:02:", because of "" year. I'd like to catch those errors in all date fields by default. Which is the best option for doing so? Thank yo very much. -- David Tanto este mensaje como todos los posibles documentos adjuntos al mismo, son confidenciales y están dirigidos exclusivamente a los destinatarios de los mismos. Por favor, si Usted no es uno de dichos destinatarios, notifíquenos este hecho y elimine el mensaje de su sistema. Queda prohibida la copia, difusión o revelación de su contenido a terceros sin el previo consentimiento por escrito Intermediación TARIC S.A.U.. En caso contrario, vulnerará la legislación vigente. Sus datos figuran en un fichero propiedad de TARIC S.A.U.. Puede ejercitar gratuitamente los derechos de acceso, oposición, rectificación, cancelación o supresión, revocación del consentimiento, portabilidad y limitación del tratamiento de los datos, dirigiéndose a TARIC S.A.U., C/ Boix y Morer, nº 6, de Madrid, con C. P. 28003. -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/SYBPR01MB4348F692D6209A41C404849FC9CC0%40SYBPR01MB4348.ausprd01.prod.outlook.com.